Add an example of undefined behaviour

This commit is contained in:
neingeist 2014-02-15 14:09:43 +01:00
parent ed40922f52
commit ffa93c8d34
3 changed files with 18 additions and 1 deletions

16
undefined-behaviour.c Normal file
View file

@ -0,0 +1,16 @@
#include <stdio.h>
int main(void) {
int a = 5;
int b = a + 7;
int c = a - b + 7;
// c is zero now!
printf("c = %i\n", c);
// Depending on e.g. the optimization level, this either throws a
// floating point exception or does other things like returning 10.
if (3/c > 4)
return 5;
return 10;
}