Conversation

twitter.com/kardonice/stat You could argue that while(1); being transformed into nothingness is well-defined. But it’s shocking for a lot of programmers. And I would be curious if any compiler actually does that in practice.
Quote Tweet
Replying to @KardOnIce @jckarter and 2 others
"[ Note: This is intended to allow compiler transfor- mations, such as removal of empty loops, even when termination cannot be proven. — end note ]"
1
The first one requires VLAs in C99, which are not supported in C++ (and never should have been supported in C, IMO), and the second requires an implicit void cast, which C++ requires the use of `reinterpret_cast` for, making the implicit cast explicit.
2
I don’t know what to believe anymore. One half of the root twitter tree says infinite loops without side effects are UB. This chain makes persuasive arguments to the contrary. What’s a decent rule of thumb regarding what to avoid in the context of loops in C/C++?
2
I think it's very clear that this was a change in semantics, but the scope of the change is very small. It also says nothing about infinite recursion. The C standard glosses over how functions are supposed to work and C implementations essentially need an infinitely large stack.
1
1
Clearly, they cannot actually have one, but the C standard does not allow undefined behavior on infinite recursion. In practice, it's going to overflow the stack, but it's not permitted to optimize it out as LLVM does in some cases due to an implementation bug. It's not allowed.
1
1
Show replies