Skip to content

Instantly share code, notes, and snippets.

@kmcallister
Created February 26, 2014 03:11
Show Gist options
  • Save kmcallister/9222833 to your computer and use it in GitHub Desktop.
Save kmcallister/9222833 to your computer and use it in GitHub Desktop.
faking top level anonymous unions
#include <stdint.h>
#include <stdio.h>
uint32_t u32 = 0;
extern uint8_t u8[4] __attribute__((alias("u32")));
int main() {
printf("%08x\n", u32);
u8[0] = 1;
printf("%08x\n", u32);
return 0;
}
@kmcallister
Copy link
Author

Doesn't work with -O2 :x Aliasing rules...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment