News for hackers. Stuff that matters.
Re:Everything in C is undefined behavior by nilamo on Wednesday May 20, 2026 @08:23AM (#48206555)
That's very funny to me.

A) x is always removed.

B) no, it's never removed if volatile.

But neither person can prove what a compiler will actually do, despite claiming they'll always act a certain way given 5 lines of code.

Re:Everything in C is undefined behavior by rcxdude on Wednesday May 20, 2026 @11:06AM (#48209058)
No, claim A is 'x may be removed by a conforming C compiler'. Whether any given version of a given compiler actually does so in any given circumstance is a different question (the answer being: probably not, because while this is undefined behaviour it's not likely something that is going to be flagged as such by a compiler's optimizer. Also, from some testing with GCC and forcing a null point dereference, it seems like volatile at least does win in that case with the current version of it x86, and it dutifully emits the null pointer dereference and then the 'ud2' instruction instead of the rest of that execution path).
Re:Everything in C is undefined behavior by tialaramex on Wednesday May 20, 2026 @08:33AM (#48206657)
Also, at behavioural edges what you'll see on Godbolt is compiler bugs. So you learn nothing about what should happen.

All popular modern C++ compilers have known bugs and while I'm sure there are C compilers with no known bugs that will be because nobody tested very hard.

Re:Everything in C is undefined behavior by dwattttt on Wednesday May 20, 2026 @09:58AM (#48207916)
I have watched a compiler flip between emitting the code I expected (despite it having UB), and emitting unexpected code after a minor update.

What you observe a compiler do when there's UB is not at all something you can rely on.

Re:Everything in C is undefined behavior by saagarjha on Wednesday May 20, 2026 @08:29AM (#48206623)
I made the weaker claim that x can be removed. This is something I could prove with compiler output but I would have to find a compiler willing to make this optimization which is not something I can guarantee.