Remix.run Logo
▲ imtringued an hour ago

Hot take: The vast majority of UB optimizations in C are just hacks to get around mutable aliasing being the default.

Edit: To be fair for the current topic it's more of an "Inverted Design-by-Contract" issue. The compiler infers the contract via UB instead of exposing it to the developer.

when you divide a/b the contract b != 0 is formed on the function signature, but never made visible. Then someone inevitably violates the invisible contract and all hell breaks loose.

    // What the developer thinks the signature is
    int f(int a, int b);

    // What the compiler secretly changed the signature to
    int f(int a, int b) 
        __attribute__((requires(b != 0))); // The invisible contract!