Skip to content

Instantly share code, notes, and snippets.

@mshroyer
Created June 25, 2012 20:25
Show Gist options
  • Save mshroyer/2991007 to your computer and use it in GitHub Desktop.
Save mshroyer/2991007 to your computer and use it in GitHub Desktop.
Example of undefined behavior in C
#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