Re:C++26: Trivial infinite loops are no longer undefined beh...
by vlovich123 on Friday September 18, 2026 @12:21PM
(#49756620)
I think the argument is that the equivalent of an infinite loop would be a halt / abort instruction, not a complete removal of the loop and continue running anything else.
[ Parent
| on HN ]
Re:C++26: Trivial infinite loops are no longer undefined beh...
by rcxdude on Friday September 18, 2026 @12:49PM
(#49756993)
Not necessarily what you want in that case either: it's a common pattern in cases where you want the system to halt until you can attach a debugger to inspect the state. A halt/abort instruction that trashes that state would be undesirable (some CPUs have an instruction that is equivalent, but many do not, after all, why bother if you can just write an infinite do-nothing loop?).
Re:C++26: Trivial infinite loops are no longer undefined beh...
by teo_zero on Saturday September 19, 2026 @02:29AM
(#49763932)
Expecting a piece of code to be compiled to a precise sequence of machine instructions is exactly what you should not do with high-level languages like C++. Their task is exactly to abstract the machine away. They give you the guarantee that the final observable result will be what you asked for, not that the means to obtain that result will be what you have in mind.
If you write a loop to zero out some memory, it can be compiled to a loop, or to a call to an optimized predefined function, or even to a sequence of single zeroing instructions, if the size is small enough.
Even a single statement as a=0 may be compiled to a "load immediate" instruction, or an "XOR with itself", or a "sub with itself", or a move from another register known to be 0.
Re:C++26: Trivial infinite loops are no longer undefined beh...
by rcxdude on Saturday September 19, 2026 @05:09AM
(#49764738)
I'm not sure what this has to do with my comment. I am aware of all of this. It would be nice if an infinite loop was defined to be 'do nothing, indefinitely'. On architectures with an instruction that works that works precisely that way, it could be turned into that, perhaps, but that's an implementation detail and should follow the as-if principle (I'm also not sure any compiler would bother).
Re:C++26: Trivial infinite loops are no longer undefined beh...
by teo_zero on Saturday September 19, 2026 @04:04PM
(#49769699)
> I'm not sure what this has to do with my comment
Because you explicitly mentioned details that belong in the implementation, not in the semantic:
> A halt/abort instruction that trashes [the] state would be undesirable
If you want to attach a debugger, then use a breakpoint, don't try to obtain the same effect within the code.
Re:C++26: Trivial infinite loops are no longer undefined beh...
by vlovich123 on Saturday September 19, 2026 @01:28PM
(#49768463)
A halt instruction is probably the appropriate representation for an infinite loop - the process gets stuck same as the infinite loop without proceeding. Abort is the instruction you want unreachable() to compile down into. It wasn’t an either or but both depending on the specific behavior you want.