In C++11, as an infinite loop with no side-effects, the following program is UB:
int main() {
while (true) {}
}
Is the following also UB?
void foo() {
foo();
}
int main() {
foo();
}
Citations from the standard for both programs would be ideal.
volatileA
before entering the loop, ifshouldExit()
does not depend onvolatileA
, in the following:while(shouldExit()) ; volatileA = false;
(assumingshouldExit()
peeks an I/O device for user input, i.e "loop forever until somebody interrupts you"). – Bibeau