Re:“gcc will quietly break nearly half of all the packages t...
by lmm on Saturday October 24, 2015 @02:21PM
(#10444410)
You don't need 4 decades of programming language research to specify that e.g. signed integer overflow either returns an implementation-defined value or the program aborting. There are languages older than C that allowed the useful forms of bit-twiddling but offered much stronger safety guarantees.
[ Parent
| on HN ]
Re:“gcc will quietly break nearly half of all the packages t...
by ridiculous_fish on Saturday October 24, 2015 @07:47PM
(#10445342)
But you pay a performance cost for either of those decisions. Consider code like this:
for (int i=0; i <= N; i++) func();
Most processors have special support for looping a fixed number of times, e.g. "decrement then branch if zero." If overflow is UB, the compiler can use this support.But if overflow returns an implementation defined value, then it is possible that N is INT_MAX and the loop will not terminate. In this case the compiler cannot use the fixed-iteration form, and must emit a more expensive instruction sequence.
Re:“gcc will quietly break nearly half of all the packages t...
by lmm on Monday October 26, 2015 @06:33PM
(#10454971)
A correctly predicted branch is almost free, the compiler could check for that case.
The real problem of course is that C requires the programmer to obscure their intent by messing with a counter variable. Is there really no "loop exactly N times" construct in the language?