Add an example of undefined behaviour
This commit is contained in:
		
							parent
							
								
									ed40922f52
								
							
						
					
					
						commit
						ffa93c8d34
					
				
					 3 changed files with 18 additions and 1 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
					@ -27,3 +27,4 @@ mtrace-test
 | 
				
			||||||
mtrace-test.trace
 | 
					mtrace-test.trace
 | 
				
			||||||
mtrace-test.txt
 | 
					mtrace-test.txt
 | 
				
			||||||
av-variance
 | 
					av-variance
 | 
				
			||||||
 | 
					undefined-behaviour
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
										
									
									
									
								
							| 
						 | 
					@ -2,7 +2,7 @@ CC=clang
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CFLAGS=-std=c99 -Wextra -pedantic -g -O0
 | 
					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
 | 
					EXTRAS=mandelbrot.bmp multibrot.png test-inline-assembly.s tags mtrace-test.trace mtrace-test.txt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.PHONY: all
 | 
					.PHONY: all
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										16
									
								
								undefined-behaviour.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								undefined-behaviour.c
									
										
									
									
									
										Normal 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;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue