Q:

How to check if the machine running on is 32 or 64 bit in C?

is there any preprocessor directive or other methods to check if the machine being run is 32 bit or 64 bit in C? I've tried googling this, but the problem with C is it brings up results for C#, C++, etc.. Also, I would prefer if this worked on Windows, Linux, and Mac.

A:

The obvious way to do this at run time.
#include <limits.h>
#include <stdio.h>

int main()
{
     printf("%d bits\n", (int)(CHAR_BIT * sizeof(void *)));
     return 0;
}

Technically, this is not 100% guaranteed to work.   Practically, this will work with most modern compilers - it is unusual for a void pointer to be represented using a number of bits that differs from that of the underlying system architecture.
To do a compile time check, there is no standard way.   It is necessary to resort to macros that are specific to your compiler/preprocessor.   You will therefore need to read relevant documentation.

