Add an example of undefined behaviour

master
neingeist 11 years ago
parent ed40922f52
commit ffa93c8d34

1
.gitignore vendored

@ -27,3 +27,4 @@ mtrace-test
mtrace-test.trace
mtrace-test.txt
av-variance
undefined-behaviour

@ -2,7 +2,7 @@ CC=clang
CFLAGS=-std=c99 -Wextra -pedantic -g -O0
TARGETS=approximate-pi linked-list mandelbrot threads circular-buffer structs ncurses-pong bit-fuckery bit-fuckery2 checkcheck multibrot bloom wo-lernen lua-foo binsearch test-inline-assembly uiowa-threads-example mtrace-test av-variance
TARGETS=approximate-pi linked-list mandelbrot threads circular-buffer structs ncurses-pong bit-fuckery bit-fuckery2 checkcheck multibrot bloom wo-lernen lua-foo binsearch test-inline-assembly uiowa-threads-example mtrace-test av-variance undefined-behaviour
EXTRAS=mandelbrot.bmp multibrot.png test-inline-assembly.s tags mtrace-test.trace mtrace-test.txt
.PHONY: all

@ -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;
}
Loading…
Cancel
Save