Skip to content

Instantly share code, notes, and snippets.

@gjb2048
Created May 19, 2013 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gjb2048/5607476 to your computer and use it in GitHub Desktop.
Save gjb2048/5607476 to your computer and use it in GitHub Desktop.
For Using C Unions on a Raspberry Pi -> https://www.youtube.com/watch?v=Q-uwhWtfy2I
#include <stdio.h>
union
{
unsigned int i;
unsigned char c;
} aunion;
int main()
{
aunion.i = 42;
printf("The answers are %d and %c\nWhy is that?\n", aunion.i, aunion.c);
printf("Unions are a facinating way of manipulating memory content\n");
printf("But can be dangerous, which is why you will not find them in Java\n");
printf("What is happening with the union 'aunion'?\n\n");
printf("And like the last video, this is fast to compile\n");
printf("But with Java you can take the .class file and run it on anything\n");
printf("with a a Java Virtual Machine.\n");
return aunion.i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment