Created
November 8, 2012 17:10
-
-
Save willglynn/4040121 to your computer and use it in GitHub Desktop.
Neither #pragma pack() nor declaration order affects linker placement of globals
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
$ make packing | |
cc packing.c -o packing | |
$ nm packing | sort | |
U dyld_stub_binder | |
0000000100000000 T __mh_execute_header | |
0000000100000f50 T _main | |
0000000100001000 S _bar | |
0000000100001010 S _foo | |
0000000100001074 S _packed_bar | |
0000000100001080 S _packed_foo | |
$ cc -v | |
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn) | |
Target: x86_64-apple-darwin12.2.0 | |
Thread model: posix |
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
char foo[97]; | |
int bar; | |
#pragma pack(push, 1) | |
char packed_foo[97]; | |
int packed_bar; | |
#pragma pack(pop) | |
int main(int argc, char ** argv) { | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment