Skip to content

Instantly share code, notes, and snippets.

@rom1v
Last active April 26, 2018 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rom1v/aa776721a2b014ba7e094f8d18473894 to your computer and use it in GitHub Desktop.
Save rom1v/aa776721a2b014ba7e094f8d18473894 to your computer and use it in GitHub Desktop.
Infinite loop that terminates (in C)
#include <stdio.h>
int f(int b)
{
while (1) {
if (b)
return 1;
}
return 0;
}
int main(void)
{
printf("f(0) returned %d\n", f(0));
return 0;
}
$ clang -O3 a.c && ./a.out
f(0) returned 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment