I want to compile code conditionally depending on the size of an integer, but I didn't quite find a way to determine the size of an integer in the preprocessor stage.
One idea is using the INT_MAX
and comparing it to a constant:
#if INT_MAX >= 9223372036854775807UL
printf("64 bit\n");
#elif INT_MAX >= 2147483647UL
printf("32 bit\n");
#else
printf("16 bit\n");
#endif
But I don't think it is guaranteed that a UL
literal can be that large. And ULL
is not available in C89 as far as I know.
So do you have any suggestions on how to solve this problem. Is there a macro that contains the size of int in some standard header maybe?
Edit:
Not a duplicate of this question because I don't actually need a generic sizeof and I don't want to print it. I only need to distinguish between distinct integer sizes for conditional compilation.