Conversation

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
In C, infinite loops are well-defined. However, in the most recent C standards, it's permitted for the compiler to assume that loops terminate if they do not have a constant expression (per restrictions on those in C) as their condition and they do not have any side effects.
1
2
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
It's also not permitted to let the stack overflow go undetected and clobber other things in memory. It's not explicitly required to detect it, but any sane implementation should reliably detect it and abort safely. Clang can't do that outside Windows. It's only safe on Windows.
1
Show replies