Saagar Jha
(replying to Wolf480pl)
Wolf480pl
(replying to Saagar Jha)
@saagar I can't see those :( I think twitter only shows them to logged-in users
Wolf480pl
(replying to Saagar Jha)
@saagar are we talking about C? is there a compiler flag that makes that happen?
Wolf480pl
(replying to Saagar Jha)
@saagar well then the compiler is defining a behaviour that was previously undefined.
You're not guaranteed by C standard that overflows will trap, but you're guaranteed by the compiler that overflows will trap.
It's not UB on that compiler (and hopefully all future versions of that compiler, and maybe other compilers that have the same nonstandard feature). It's just non-portable code.
1/
Wolf480pl
(replying to Wolf480pl)
That being said I agree that teaching "UB is black box" is wrong. It's best to show an example how a seemingly innocent UB can cause an optimizing compiler to make assumptions and delete half of your code.
2/2