3 ms·
> It's easy to pick on undefined behavior in C when you focus on the more gratuitous undefined behaviors ... That is the whole point. There are scores of inst
by bhk 5y ago
> It's easy to pick on undefined behavior in C when you focus on the more gratuitous undefined behaviors ...
That is the whole point. There are scores of instances of gratuituous UB.
> 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.
Traps are not inherently undefined. The C standard discusses floating point traps in detail. Many details may of course be left to the implementation or platform to describe, but that's very different from saying "all bets are off".
The real reason for the gratuitous UB was misunderstanding and ignorance.
> Hopefully, you'll agree that that is a reasonable optimization.
Hopefully, you'll agree that the code is buggy, and should be fixed. We end up running expensive and cumbersome static analysis tools that try to detect situations just like this ... which the compiler itself has detected, but chosen not to warn us.
- richardwhiuk 5y agoThe first code isn't necessarily buggy.