Re:Tell HN: C Experts Panel – Ask us anything about C
by temac on Tuesday April 14, 2020 @06:05PM
(#22872066)
I thought the compiler was free to pretend loops without side effects always terminate, and in that sense it is already a "correct" optimization? Or is it only for C++, I'm not sure?
[ Parent
| on HN ]
Re:Tell HN: C Experts Panel – Ask us anything about C
by pascal_cuoq on Tuesday April 14, 2020 @06:45PM
(#22872396)
That may be the case in C++, but in C infinite loops are allowed as long as the controlling condition is a constant expression (making it clear that the developper intends an infinite loop). These infinite loops without side-effects are even useful from time to time in embedded software, so it was natural for the committee to allow them: https://port70.net/~nsz/c/c11/n1570.html#6.8.5p6
And you now have all the details of the Clang bug, by the way: write an infinite loop without side-effects in a C function, then call the function from another C function, without using its result.