News for hackers. Stuff that matters.
Re:Everything in C is undefined behavior by saagarjha on Wednesday May 20, 2026 @07:52AM (#48206248)
No this is irrelevant for making this decision
Re:Everything in C is undefined behavior by shakna on Wednesday May 20, 2026 @08:01AM (#48206337)
I've mentioned elsewhere the standards, and compilers as well, disagreeing with you here.

But feel free to run against the various compilers through godbolt. [0] They won't optimise the branch away. Access to a volatile, must be preserved, in the order that they exist. No optimisation, UB or otherwise, is allowed to impede that. Because an access is a side-effect.

[0] https://godbolt.org/z/85cGhq3Ta

Re:Everything in C is undefined behavior by saagarjha on Wednesday May 20, 2026 @08:17AM (#48206487)
That they won’t is as most a courtesy to you but they are not required to do this.
Re:Everything in C is undefined behavior by shakna on Wednesday May 20, 2026 @08:26AM (#48206591)
> Furthermore, at every sequence point the value last stored in the object shall agree with that prescribed by the abstract machine, except as modified by the unknown factors mentioned previously.

I quoted the C standard, first. Not compiler behaviour.

I showed where it requires the compiler not to optimise this.

How about, instead of one-line throwaway disagreements, you point out where they are permitted to do this, instead?

Re:Everything in C is undefined behavior by dwattttt on Wednesday May 20, 2026 @09:56AM (#48207881)
The compiler is required to not optimise out reads/writes through volatile. That's unrelated to code also having UB: you can't sprinkle volatile through arbitrary UB and suddenly have it be defined.

> A compliant compiler is only free to optimise away, where it can determine there are no side-effects

A compliant compiler is also allowed to assume UB cannot occur.

Re:Everything in C is undefined behavior by zahlman on Wednesday May 20, 2026 @09:58AM (#48207911)
Compilers not doing something is not a demonstration that they are not actually allowed to do that thing.