Detecting 64bit compile in C
Solution 1:
Since you tagged this "gcc", try
#if __x86_64__
/* 64-bit */
#endif
Solution 2:
Here is the correct and portable test which does not assume x86 or anything else:
#include <stdint.h>
#if UINTPTR_MAX == 0xffffffff
/* 32-bit */
#elif UINTPTR_MAX == 0xffffffffffffffff
/* 64-bit */
#else
/* wtf */
#endif
Solution 3:
An easy one that will make language lawyer squeem.
if(sizeof (void *) * CHARBIT == 64) {
...
}
else {
...
}
As it is a constant expression an optimizing compiler will drop the test and only put the right code in the executable.