C++26: Trivial infinite loops are no longer undefined behaviour
Thread
Unofficial Hacker News client; not affiliated with Y Combinator.
C++26: Trivial infinite loops are no longer undefined behaviour
Unofficial Hacker News client; not affiliated with Y Combinator.
BobbyTables2 · · focus · HN ↗
Idiots!
Don’t they really that people write real programs to solve real problems? This isn’t a theoretical academic exercise!
bluGill · · focus · HN ↗
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.
echoangle · · focus · HN ↗
bluGill · · focus · HN ↗
echoangle · · focus · HN ↗
bluGill · · focus · HN ↗
Now that I think of it, a different project (I worked just down the aisle, but I wasn't on it) solved a lot customer complaints by turning all the "while(1);" loops into blink an error code - which since it does IO is defined behavior. Which probably is the correct answer to your question - don't just spin doing nothing, spin in such a way that the user has a clue why nothing is working (and in turn you can find out and perhaps fix real world bugs)
dare944 · · focus · HN ↗
There's no need to inform the "user" because there's nothing wrong with the system. Its simply waiting until the benefit of sleeping outweighs the cost of getting there.
bluGill · · focus · HN ↗
echoangle · · focus · HN ↗
dare944 · · focus · HN ↗
Now if your processor has a halt/wait-for-interrupt instruction (most do but some don't) you can escape into assembly and use that. But it probably makes little to no difference to energy utilization, and of course its not portable. A nice while (true); would seem obvious, except that the C++ committee insisted that it wasn't.
Just one example of where the committee lost sight of the fact that it was defining an imperative programming language.
AMDmi3 · · focus · HN ↗