3 ms·
Well that's interesting. I was not aware of any compilers doing this. I wonder if there's a switch in gcc/llvm/msvc/etc to turn this specific behavior off.
by dpark 9y ago
Well that's interesting. I was not aware of any compilers doing this. I wonder if there's a switch in gcc/llvm/msvc/etc to turn this specific behavior off.
- majewsky 9y agohttps://linux.die.net/man/1/gcc https://linux.die.net/man/1/gcc -- Search for `-fstrict-overflow`. And note how it says The -fstrict-overflow option is enabled at levels -O2, -O3, -Os. In other words, basically every program that you're using is compiled with that option enabled. (Release builds typically use -O2, sometimes even -O3.)
- osandov 9y ago-fstrict-overflow is the opposite of what the parent comment was asking about. You want -fwrapv or -fno-strict-overflow.
- majewsky 9y agoI was answering the "not aware that any compilers were doing this" part, hoping that they would be able to answer their second question using the source I linked.
- eru 9y agoBasically all C and C++ compilers do this. They do it, so they can simplify things like "x < x+1" to "true".