Comment by jolux

3 years ago

> using any gap in the standard to miscompile code

For code to be miscompiled, there has to be a definition of what correctly compiling it would mean, and if there were, it would not be undefined behavior.

Instead of "miscompiled" you can read "Doesn't do what it did on the PDP-11 with the compilers of the time".

Yeah, but if that definition is constantly shifting, you cannot expect it to work with existing codebases.

  • Well yeah — therein lies the problem with a language with pervasive undefined behavior.

The standard doesn't do that often, but it does sometimes. E.g. realloc to null which was previously defined, and is now UB :(

  • We are taking about code written before the standard so every bit of UB in the standard is in play here.

    Eg the fact that overflowing a signed int can cause the compiler to go amuck would certainly be a surprise to the person who wrote code for the PDP-11.