Remix.run Logo
▲ jcranmer 3 hours ago

> [1] Said person said the appendices to C99 aren’t authoritative, but if something is in the spec, including in the appendices, it’s authoritative.

That's not true. There is a difference between normative text and informative text. Informative text is not authoritative, and you were citing an appendix that is labeled as informative.

> I am hoping the up and coming C2y spec has very clearly defined behavior when using unintialized memory (ideally where it will work but the bytes can have any values).

It won't. Uninitialized memory can't have "very clearly defined behavior" without breaking essentially every single implementation, and WG14 is very loth to break existing implementations.

▲rallyrascal 16 minutes ago | parent | next [-]

How would it break existing implementations?

Having accessing uninitialized memory be UB is just insane, there's only two possible sane implementations - potential trap for caps based systems (or for a static analyzer) or you get a pseudo random value i.e 'whatever happened to be there'. So just make it implementation defined.

▲afdbcreid 3 hours ago | parent | prev [-]

> It won't. Uninitialized memory can't have "very clearly defined behavior" without breaking essentially every single implementation, and WG14 is very loth to break existing implementations.

You can initialize with some bit pattern. This is what was accepted for C++ (but only for certain types of memory).

▲vbezhenar 2 hours ago | parent [-]

That's huge performance loss. Imagine doing useless initialization of multi-megabyte chunk of memory. Not acceptable for C programs.

In fact I hate that C mandates static variables being initialized to zero. This is dumb. When I'm writing for MCU, that's useless cycles spent at the power on. Thankfully it's possible to fix with linker tricks, but it should not be an issue in the first place.

▲afdbcreid 37 minutes ago | parent | next [-]

I agree it is, and like the other commenter said even C++ only did it for some things. I was only saying it is not breaking.

▲aw1621107 an hour ago | parent | prev [-]

In the case of C++ initialization is (currently) only done for automatic variables, so you're not likely to be zero-initializing multiple megabytes of stack. There's also [[indeterminate]] for opting out of initialization, though that has to be done per variable.