Created
June 25, 2012 20:25
-
-
Save mshroyer/2991007 to your computer and use it in GitHub Desktop.
Example of undefined behavior in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdbool.h> | |
int main(int argc, char *argv[]) | |
{ | |
bool b; | |
*((unsigned char *)&b) = 0xff; | |
if ( b ) | |
printf("b is true\n"); | |
else | |
printf("b is not true\n"); | |
if ( ! b ) | |
printf("b is false\n"); | |
else | |
printf("b is not false\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment