diff --git a/.gitignore b/.gitignore index d6fd42d..754b15a 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ mtrace-test mtrace-test.trace mtrace-test.txt av-variance +undefined-behaviour diff --git a/Makefile b/Makefile index 0413141..adf2627 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/undefined-behaviour.c b/undefined-behaviour.c new file mode 100644 index 0000000..e7b0c8c --- /dev/null +++ b/undefined-behaviour.c @@ -0,0 +1,16 @@ +#include + +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; +}