This simple C program rarely terminates at the same call depth:
#include
#include
void recursive(unsigned int rec);
int ma
Your recursive call is not necessarily going to cause undefined behaviour due to stackoverflow (but will due to integer overflow) in practice. An optimizing compiler could simply turn your compiler into an infinite "loop" with a jump instruction:
void recursive(int rec) {
loop:
printf("%i\n", rec);
rec++;
goto loop;
}
Note that this is going to cause undefined behaviour since it's going to overflow rec
(signed int overflow is UB). For example, if rec
is of an unsigned int, for example, then the code is valid and in theory, should run forever.