Code:
if(sizeof(int*) == 4)
//system is 32-bit
else if(sizeof(int*) == 8)
//system is 64-bit
or
Code:
gcc -arch i386 -arch x86_64 somefile.m -o somefileUniversal
I actually copy & paste the above c program and that what I found out.
sizeof(int*) can only indicate if the application is 32-bit or 64-bit but not the kernel. I boot into 32-bit kernel and sizeof(int*) show me that system is 64-bit.
uname -a
Darwin SL106s-Mac-Pro.local 10.7.0 Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386 i386
g++ my32.cpp -arch i386 -arch x86_64 -o my32
file my32
my32: Mach-O universal binary with 3 architectures
my32 (for architecture i386): Mach-O executable i386
my32 (for architecture x86_64): Mach-O 64-bit executable x86_64
my32 (for architecture ppc7400): Mach-O executable ppc
SL106s-Mac-Pro:mycpp sl106$ ./my32 &
[1] 946
SL106s-Mac-Pro:mycpp sl106$
size of int* is 8
system is 64-bit
if I compile to 32-bit
g++ my32.cpp -arch i386 -o my32
SL106s-Mac-Pro:mycpp sl106$ ./my32
size of int* is 4
system is 32-bit
^C
SL106s-Mac-Pro:mycpp sl106$ file my32
my32: Mach-O executable i386
SL106s-Mac-Pro:mycpp sl106$
The same program execute on 64-bit kernel will show it is 32-bit as well.
I think foidulus is the correct way.
gcc's option of -arch i386 or -arch x86_64 only tell the gcc to build 32-bit or 64-bit application but it is not related if the running kernel is 32-bit or 64-bit.