4 ms·
If my signed integers overflow, that is wrong. I want to be able to detect if it ever happens, not have that be defined as perfectly valid wrapping behavior.
by celrod 3y ago
If my signed integers overflow, that is wrong.
I want to be able to detect if it ever happens, not have that be defined as perfectly valid wrapping behavior.
If it's undefined, it's perfectly legal for the compiler to make overflow trap, so I can catch it, or confirm it never happens when running tests our debugging.
`-ftrapv` or ``-fsanitize=undefined` do this.
- xscott 3y agoTo each their own. I want my 64 bit integers to do what the CPU does, and I could bore you with useful examples where two's complement wrap around is exactly the right behavior. But more importantly, I don't ever want to worry about stumbling into undefined behavior, and compiler extensions like -ftrapv or -fwrapv are not part of the standard. I can't count on those being there when I switch compilers, and if I write a library for others, I can't count on the application developer using the flags I need.