3 ms·
They are called undefined behaviors because the compiler developers are free to do whatever they want when they come across a code that instigates an undefined
by fazkan 9y ago
They are called undefined behaviors because the compiler developers are free to do whatever they want when they come across a code that instigates an undefined behavior.
Mostly new compilers now a days do handle such behavior with a compiler error or warning. So if you try to do an out of bound shift a new compiler might throw a warning, but according to the C standard it does not have to. In fact instead of throwing a warning it can wipe your complete hardware and that too is allowed according to the C standard...
In contrast there is implementation defined behavior, and unspecified behavior. Where the compiler developers have to document and take care of certain things.
I wrote a detailed article about the subtle difference you can check that out....
https://medium.com/@faizan10114/understanding-c-terminologies-a-dummies-perspective-695af2648289 https://medium.com/@faizan10114/understanding-c-terminologie...
- dom0 9y ago> So if you try to do an out of bound shift a new compiler might throw a warning, but according to the C standard it does not have to. Right, for doing so needs to determine that this is happening, which neither GCC and Clang can do for fairly trivial cases like for (i = 0; i < 100; i ++) { ... x << i ... }
- fazkan 9y agoYes they don't, I assumed they would, but they dont. I just wanted to emphasize the fact that they don't have to. Perhaps an unbound shift was a wrong example.. thanks for catching that...