logoalt Hacker News

AlotOfReadingyesterday at 6:27 PM2 repliesview on HN

It's valuable for compilers to be able to choose the instruction scheduling order. Standards authors try not to unnecessarily bind implementors. If post increment happened after the full statement is finished, then the original value has to be maintained until the next sequence point. Maybe the compiler will be smart enough to elide that, maybe not, but it's a lot more difficult to fix those kinds of edge cases than to say sequencing is undefined.


Replies

Aardwolfyesterday at 6:29 PM

But this is not valuable if doing so results in different numerical results, and I think that will always happen if ++ is executed at different times, there's no point in a compiler optimizing pointless code that can silently give different results elsewhere

show 1 reply
xigoiyesterday at 6:42 PM

It would only make a difference in cases that are currently UB, so there is no program valid under current C that would be pessimized by this change.

show 1 reply