Detecting 64bit compile in C Detecting 64bit compile in C unix unix

Detecting 64bit compile in C


Since you tagged this "gcc", try

#if __x86_64__/* 64-bit */#endif


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


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.