Top
Best
New

Posted by ibobev 5 days ago

C++26: Trivial infinite loops are no longer undefined behaviour(www.sandordargo.com)
173 points | 288 commentspage 2
aabolfazl 4 days ago|
Sometimes while (true){} doesn't mean anything clever. It just means the system is broken stay here.
paparulo329 4 days ago||
The mere concept of undefined behavior is hilarious to me. "Oh this part? No we can't and won't even try figuring out what doing that does, this page intentionally left blank; yes we are a very serious whole ass standards body thanks for asking"
layer8 4 days ago|
The purpose is to free optimizers from solving the halting problem (and similar undecidable propositions), which they can’t. So the approach is to reduce the allowable programs to those that optimizers can reliably reason about. By the very nature of the problem, these programs cannot in general be distinguished by an algorithm, because again that would require solving the halting problem. So the non-allowable programs are simply declared to be out-of-scope (aka UB).

It’s a controversial trade-off to be sure, but it’s not like there isn’t a sound logic to it.

MiroslavPokorny 5 days ago||
Breadcrumbs for "blog", "year", "month" etc are broken and give 404s :(

One can browse other blog entries so it really doesnt matter too much.

0x69420 4 days ago||
> The mentioned proposal was also accepted as a defect report, so implementations may apply the fix to earlier C++ modes as well. That is why you might not be able to reproduce the old behaviour on a recent compiler even in C++20 mode.

brutal. hope major compiler vendors throw in a flag that can bring some sanity to this

Surac 4 days ago||
For me everything more than c with classes is too much cognitive load. Templates my by ok for implementing Generics but most of the other changes this comitee has produces are complete waste of brain i think
kazinator 4 days ago||
I'd much rather have the compiler diagnose an infinite loop than silently pretend that it's not reachable, or that it can be rewritten to a yield.

In other words, I am mentally well.

WalterBright 4 days ago|
There's no way for a compiler to reliably determine that a loop is infinite, making it very difficult for the standard to require such determinations.
bitbasher 4 days ago||
If an infinite loop can be both:

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!

mwkaufma 4 days ago||
If it's one of those two it's not fully undefined behavior it's just implementation defined. UB can do anything.
cppcppcpp 4 days ago||
You know what you’re getting, the code is right there!
ratelimitsteve 4 days ago||
as the kind of person who has been reading the jargon file for fun since the 90s, I thought I had at least a passing familiarity with a lot of hackish slang from the old days. today i learned about nasal demons as a phrase for undefined behavior. i supposed there's still fossils in the dirt
shmerl 4 days ago||
Why does the loop mean halt in that embedded case example?
rcxdude 4 days ago|
It just spins the CPU in the loop, stopping execution from progressing. Technically, whether this fully halts the system depends on what else is going on: you might need to fully disable interrupts before entering the loop to get a full halt. OTOH you can design your system so that everything happens in interrupts (with modern interrupt controllers the common wisdom of doing as little as possible in interrupts no longer applies and it can be a good way to get a predictable and low-latency system) and so you finish your setup code with an infinite loop to stop the CPU running off the end of your function when it's not executing one of the interrupts.

In a lot of cases, you might insert some 'wait-for-interrupt' type instruction in the loop that halts the CPU more 'cleanly' (and in a lower power mode), and usually this will appear as a side-effect and keep the behaviour defined. But this is not always desirable or possible.

z3ratul163071 4 days ago|
c++ reaching new lows
cppcppcpp 4 days ago|
This is good for Rust!
layer8 4 days ago||
This actually fixes a case that became a problem for Rust implementations: https://github.com/rust-lang/rust/issues/28728

So yes, it is good for Rust.

kibwen 4 days ago||
The Rust case was fixed back in 2021 via changes to LLVM, it didn't require waiting for the C++ standards body.
More comments...