‹ BackHN Continuity

Thread

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

173 points · 290 comments · ibobev

  1. BobbyTables2 · · focus · HN ↗
    TLDR: For almost 1/6 of a century, the C++ standards broke the simplest infinite loop and only just recently fixed it.

    Idiots!

    Don’t they really that people write real programs to solve real problems? This isn’t a theoretical academic exercise!

    1. bluGill · · focus · HN ↗
      You are an idiot if you write an infinite loop. An infinite loop is a waste of CPU cycles and energy when run.

      If it wasn't so hard to detect (the trivial cases are easy, but it gets hard quickly) I'd say the program should fail to compile.

      1. dare944 · · focus · HN ↗
        And where to you think all that "wasted" energy/cycles would go otherwise? Why do you presume there's some other, more efficient way the CPU could be spending its time while waiting for an event to process?

        I, the programmer, will decide what cycles are wasted or not. That the C++ committee thought they knew better is hubris.

        1. bluGill · · focus · HN ↗
          If the CPU halts it isn't used at all. If the CPU does an infinite loop then it all goes to heat.

          If the loop is doing anything then it cannot be optimized away. Only loops with no side effects meaning they are just turning the CPU into a heater count.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.