← Back to context

Comment by ErikCorry

3 years ago

The library my dad wrote (lol) for the PDP-11 is probably full of undefined behaviour and won't work now that optimizers are using any gap in the standard to miscompile code.

> 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.

What a useless and jaded assumption that code written in the past is bad.

  • The assumption being made here is "any useful C program relies on undefined behavior" which is pretty much true.

  • I certainly didn't say it was bad. Just that it went outside the boundaries of a standard that was written 25 years later.