Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Created September 14, 2012 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TooTallNate/3723332 to your computer and use it in GitHub Desktop.
Save TooTallNate/3723332 to your computer and use it in GitHub Desktop.
Detecting arch of a fat binary using the preprocessor
#include <stdio.h>
int main () {
if (sizeof(int*) == 4) {
printf("ia32\n");
}
if (sizeof(int*) == 8) {
printf("x64\n");
}
return 0;
}
$ gcc -o arch-test arch-test.c -arch i386 -arch x86_64
$ ./arch-test
x64
$ arch -32 ./arch-test
ia32
$ arch -64 ./arch-test
x64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment