Skip to content

Instantly share code, notes, and snippets.

@yang
Created February 13, 2009 23:28
Show Gist options
  • Save yang/64162 to your computer and use it in GitHub Desktop.
Save yang/64162 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cstring>
#include <iostream>
#include <type_traits>
using namespace std;
enum { sz = 8 };
int main() {
cout << alignment_of<int>::value << endl;
char a[sz];
cout << (void*)a << endl;
bzero(a, sz);
*((int*)(a+1)) = -1;
for (int i = 0; i < sz; ++i) printf("%02hhx ", a[i]);
cout << endl;
return 0;
}
#if 0
Here's the stdout on x86_64:
4
0x7fff0710a2b0
00 ff ff ff ff 00 00 00
How did gcc make the unaligned write work? Did it just generate inefficient code? I expected a cast-align warning or something.
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment