It's easy to pick on undefined behavior in C when you focus on the more gratuitous undefined behaviors such as signed overflow or oversized shifts. I'm not certain why these are undefined behavior instead of implementation-defined, but my suspicion is that these caused traps on some processors, and traps are inherently undefined behavior. Instead, if you dislike undefined behavior, I challenge you to come up with wor…
I'll bite. > int x = cond ? 2 : y; /* Is it legal to fold this to int x = 2; ? */ This is permissible (on typical hardware) only if the implementation chooses to 'initialize' y to 2 (possibly skipping the actual write if it is later overwritten), since doing otherwise would result in: int x1 = cond1 ? 2 : y; /* So int x1 = 2; */ int x2 = cond2 ? 3 : y; /* So int x2 = 3; */ No, no it may not do that. Edit1: actually,…
Hardware doesn't define C semantics. C defines C semantics. I don't understand what your conditional example is trying to say, but you seem to assume that an uninitialized y is an actual uninitialized register or memory location. It's not.
>> A function marked _Noreturn returns.
> If written in C, the body of the function must include a return statement, and is thus a compile time error.
It might contain a return statement that is never reached because the function goes into an infinite loop or exits/aborts the program or does a longjmp.