170 points by ibobev 3 days ago | 282 comments | View on ycombinator
wahern 2 days ago |
JoshTriplett 2 days ago |
Insert screaming here.
An infinite loop, with no library calls whatsoever, gets a system call inserted. That's a horrible surprise waiting to happen.
The entire concept of the "forward progress guarantee" is broken. An infinite loop should compile to an infinite loop. Nothing more, nothing less.
omoikane 2 days ago |
This seems to say that the loop body can not be "continue". Indeed, I just tried -std=c++26 with ";" and got an infinite loop as promised, but "continue" restores the undefined behavior:
- "while(true);" -> https://godbolt.org/z/T65o51crx
- "while(true) continue;" -> https://godbolt.org/z/Pj9raEcnP
This is unfortunate since I know of one style guide that prefers "continue" over single semicolons. I guess all those code will be doing "while(true) {}" from now on.
https://google.github.io/styleguide/cppguide.html#Formatting...
ameliaquining 2 days ago |
peterus 2 days ago |
I only use it for error handling and of course it is a bad idea to use this to wait/stall in power sensitive applications, in that case use wake from interrupt.
As an aside, I like to include a software breakpoint in my error handlers. It makes debugging easier without wasting a hardware breakpoint (which are physically limited by the microcontroller):
__BKPT();
while (1)
;Panzerschrek 2 days ago |
ErikCorry 2 days ago |
If be curious if these are the sorts of optimizations I would find useful to the point where I would be happy to pay the price of this annoying new behaviour.
Or are they just the sorts of optimizations that a compiler writer finds useful who is engaged in a multi year career-defining pissing contest with a competing team?
Don't get me wrong, I have myself engaged in a multi year career-defining pissing contest with a competing team. It's fun. But let's not kid ourselves that it's for the users' sake.
Aardwolf 2 days ago |
Why is that rule needed? I could make my for loop try to solve the halting problem and it'll never finish either, circumventing that rule
Aurornis 2 days ago |
adzm 2 days ago |
paparulo329 2 days ago |
aabolfazl 2 days ago |
MiroslavPokorny 3 days ago |
One can browse other blog entries so it really doesnt matter too much.
Surac 1 day ago |
0x69420 2 days ago |
brutal. hope major compiler vendors throw in a flag that can bring some sanity to this
kazinator 2 days ago |
In other words, I am mentally well.
bitbasher 2 days ago |
1. An infinite busy loop.
2. A thread yield/sleep.
It is by definition undefined behavior. You don't know what you're going to get!
ratelimitsteve 2 days ago |
kmarc 1 day ago |
... thankfully. Gives many of us well-paid jobs, and the inexplicable joy of archeology (why certain decisions were made at some point in the nineties, and what buggy implementation a bits header is fixing).
And I'm not even snarky here. I kinda like to do this.
z3ratul163071 2 days ago |
shmerl 2 days ago |
deepsun 2 days ago |
I'm more surprised it passed through the committee, they should've seen that back in 2011. I can not imagine such a bug in spec would pass through a Java committee, as they discuss every little thing for years (sometimes decades). It's not like embedded code is something new.
oleganza 2 days ago |
ahy1 2 days ago |
There are good uses for infinite loops.
adzm 2 days ago |
glum64 2 days ago |
pianom4n 2 days ago |
BobbyTables2 2 days ago |
Idiots!
Don’t they really that people write real programs to solve real problems? This isn’t a theoretical academic exercise!
semiinfinitely 2 days ago |
account42 2 days ago |
Dwedit 2 days ago |
Not just X (em dash) but also Y.
That's the epitome of the hidden code downside that Linus and many others dislike about C++. For constructors and destructors it's somewhat unavoidable and not so random, though Rust does better at limiting the blast radius of non-local code, at least in the drop case.
If they didn't want to adopt the C11 rule, the C++ committee should've explored a rule that required the compiler to emit a diagnostic or error for trivial loops (whether as defined by C11 or otherwise), requiring the programmer to explicitly insert ::yield or similar. No hidden code, and less opportunity for the compiler to do surprising things.
The C committee has been rigorously enumerating UB cases in the standard and addressing each case in turn, often by requiring a diagnostic, error, or by turning it into implemention defined behavior. But inserting code like that would be unthinkable.