‹ BackHN Continuity

Thread

C++26: Trivial infinite loops are no longer undefined behaviour

173 points · 290 comments · ibobev

  1. oleganza · · focus · HN ↗
    Why is null-terminated C string considered a "billion dollar mistake", but UB isn't?
    1. fooker · · focus · HN ↗
      This comes from a fundamental misunderstanding of what UB is.

      Think of this piece of code - `y * x / y`.

      Would you like to simplify it to just `x` ?

      You need to either lean on UB to do so or have some magical way to prove that y can not be 0.

      Otherwise this transformation changes behavior, and is illegal.

      1. colejohnson66 · · focus · HN ↗
        Why not just execute what I wrote? Maybe I'm doing some rounding?
        1. layer8 · · focus · HN ↗
          Because we want compilers to perform the optimizations, not programmers.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.