3 ms·
> This is pretty much obviously an error! No, in most cases that's the result of defensive programming and macros or inlining, where there is a perfectly usefu
by zAy0LfpBZLC8mAC 10y ago
> This is pretty much obviously an error!
No, in most cases that's the result of defensive programming and macros or inlining, where there is a perfectly useful sanity check in some inlined function, but the compiler can see that in some specific context where it was inlined, the check is actually redundant, and thus removes it.
> Since UB is rare, we can even arrange things such that the branch doesn't slow down the CPU in the general case.
It's an additional instruction, so it always has the potential to slow the code down, if only because it makes the code bigger than the cache. Also, it's usually not one such branch, but lots and lots of them throughout the program. That's why the optimizer tries to eliminate them.