Created
February 13, 2009 23:28
-
-
Save yang/64162 to your computer and use it in GitHub Desktop.
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 <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