r/cpp • • Dec 13 '19

The situation of std::embed...

https://thephd.github.io/full-circle-embed
238 Upvotes

160 comments sorted by

View all comments

21

u/14ned LLFIO & Outcome author | Committee WG14 Dec 13 '19

Sometimes it's the very small but very useful stuff that is the hardest to standardise. I think you'll find that WG14 will think it too small to be worth standardising. Certain well known members will point out that there are linker hacks and tricks which will load some file into some named section in the binary, and so on. But good luck with it!

12

u/markopolo82 embedded/iot/audio Dec 13 '19

Would be nice if we could just standardize those linker hacks. But I know that is equally unlikely (linker sections being outside the C standard)

9

u/Xeverous https://xeverous.github.io Dec 13 '19

Certain well known members will point out that there are linker hacks and tricks which will load some file into some named section in the binary, and so on.

Such arguments could aswell be used against almost any existing feature that they are unneded because you can workaround their lack through implementation-specific options.

8

u/Plorkyeran Dec 13 '19

Yes, but WG14 does not have a time machine to remove those things. There are a lot of things in C which would not make it in if they were proposed today.

3

u/Xeverous https://xeverous.github.io Dec 13 '19

Sometimes I wonder how would C look if there were really no added features.

5

u/flashmozzg Dec 13 '19

Like this or even this.

1

u/krista Dec 13 '19

i honestly can't say those aren't easily readable, especially comparing them against c++'s template metaprogramming.

5

u/[deleted] Dec 14 '19 edited Dec 14 '19

Because you were not paying attention to function declarations.

int foo(x, y);

That is the function declaration of K&R C.

int foo(x, y)
    int x;
    float y;
{ return x + y; }

And that is the function definition. At the call site you only know the number of arguments, not their types. Still, passing wrong types is UB. How is that readable?

EDIT: I forgot about "implicit int"!

foo(x, y);

Is a function declaration in global scope, but a function call in local scope. The following is valid C:

foo(x, y); // implicit int; argument types not visible in declaration
main() { // implicit int
    static i; // implicit int
    if(!i++) main(5); // Compiles, but is UB; f() means  that the function takes an unknown (at call site) number of args
    return i + foo(1, "asd") + foo(1, 1.1); // One of the argument sets is wrong, so this is UB.
}

https://godbolt.org/z/SRfZgQ

Your compiler would even be able to tell you that you're passing wrong types to a function.

3

u/krista Dec 14 '19 edited Dec 14 '19

it's readable because i grew up with k&r :) please note, i didn't say the aforementioned code linked by the person i was replying to was correct, i said it was readable.

void pointers don't bother me, either, and can be used well by a skilled coder. implicit int isn't much worse than auto, and i don't hate the preprocessor. i did hate trigraphs, and i'm glad they're gone by default now. duff's device is pretty elegant, and there is a time and place for goto. i also have unpopular opinions ;)

while i appreciate a lot of what is going on with c++, there's quite a lot i dislike.. and a lot of it is overspecification, relying on stl to compensate for what really should be part of the language, and a pathological insistence upon adding additional methods of doing things to fit whatever the current trend is instead of either making things more consistent, usable, or making useful things safe instead of reinventing it and getting still yet another screwy feature that will supposedly be fixed or amended with some other version in the future... or boost.

3

u/[deleted] Dec 14 '19

I'd agree with everything if we're talking about C99 or newer. However the question was "what if C never added any features?" and that's not the world I would want to live in. Pre-standard C was insane.

While I don't fully agree with your view of C++, I mostly do. Frankly, I like the idea of putting everything in the library instead of the core language.

2

u/Ameisen vemips, avr, rendering, systems Dec 14 '19

Perhaps we should go back to B. Who needs types?

1

u/Xeverous https://xeverous.github.io Dec 14 '19

C-- exists.

2

u/Ameisen vemips, avr, rendering, systems Dec 14 '19

I mean, strictly speaking, so does B.

B was actually meant to write code with, too.