‹ 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. echoangle · · focus · HN ↗
        And how would you generate assembly to keep a microcontroller idle then?
        1. bluGill · · focus · HN ↗
          You call the CPU halt instruction.
          1. echoangle · · focus · HN ↗
            What if my CPU doesn't have that? I don't think Atmel Microcontrollers do for example.
            1. AMDmi3 · · focus · HN ↗
              AVRs have SLEEP instruction.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.