Refer to the parallel thread in this chain. There is a long discussion about it, and the consensus seems to be that infinite loops either were or are undefined behavior in some cases.
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
This not a quote from any C standard, and certainly not C99. It's about C++11, not C11, and definitely not C99.
1
1
Yeah, completely different thread and standards being referenced. Daniel's reference C11, I'm referencing C++11, and both in very different contexts.
1
Then can we agree that since C is a subset of C++, there exist some dialects and versions of C and/or C++ where while(1); is undefined behavior?
2
C is absolutely not a subset of C++. Anyone who claims such either does not know C or does not know C++, full stop.
1
3
Could you point out a construct that is valid in C99 but invalid in C++?
1
void func(int x) {
int [x] arr;
}
Will that do it for you?
For how about?
char* x = malloc(5);
1
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
Designed initializers, restrict and a bunch of other C99 / C11 features were also not adopted by C++. My example demonstrates that C89 is not a subset of any C++ standard though. There are other examples of that but it's what first comes to mind when I think about differences.
2
1
C89 isn't far from being a subset of C++, but it isn't one. Another trivial example is that C++ reserves more keywords and will break C code using those as names (like class) but it's less interesting than differences like 'c' really being an int constant in C and char in C++.


