Search code examples
cc-preprocessorunsigned-long-long-int

Check if unsigned long long is available


How can i check by a preprocessor directive if the type unsigned long long is available in the current build environment?

I tried checking

#if __STDC_VERSION__ >= 199901L
    /* Available */
#else
    /* Not available */
#endif

but compiling with gcc and at least without -std=-compiler argument this leads to "Not avaibalble" (but would work).

Is there a better macro to check so that at least it works with C99 standard compilers and with GCC without -std=C99?


Solution

  • Although it is not the most elegant of solutions, my first instinct would be to check for the existence of the ULLONG_MAX symbol in the limits.h header.

    If it is defined, then the unsigned long long int type is almost certainly available. If it is not defined, then the type is probably not available—or at least, it is not well-supported and may only be available as a non-portable compiler extension.