News for hackers. Stuff that matters.
Re:Undefined Behavior in 2017 by fazkan on Wednesday July 05, 2017 @04:22AM (#14700723)
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-terminologie...

Re:Undefined Behavior in 2017 by dom0 on Wednesday July 05, 2017 @04:26AM (#14700740)
> 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 ...
    }
Re:Undefined Behavior in 2017 by fazkan on Thursday July 06, 2017 @04:21AM (#14708892)
Yes 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...