Skip to content

Instantly share code, notes, and snippets.

@OneSadCookie
Created October 8, 2011 01:29
Show Gist options
  • Save OneSadCookie/1271719 to your computer and use it in GitHub Desktop.
Save OneSadCookie/1271719 to your computer and use it in GitHub Desktop.
OneSadMBP13:Desktop keith$ cat > test.c
#include <stdio.h>
typedef struct { short a; } S;
typedef struct { char a[2]; } T;
main(){
printf("short: %zu bytes; aligned to %zu\n", sizeof(S), __alignof__(S));
printf("char[2]: %zu bytes; aligned to %zu\n", sizeof(T), __alignof__(T));
return 0;
}
OneSadMBP13:Desktop keith$ gcc test.c
OneSadMBP13:Desktop keith$ gcc -arch i386 -arch x86_64 test.c
OneSadMBP13:Desktop keith$ ./a.out
short: 2 bytes; aligned to 2
char[2]: 2 bytes; aligned to 1
OneSadMBP13:Desktop keith$ arch -i386 ./a.out
short: 2 bytes; aligned to 2
char[2]: 2 bytes; aligned to 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment