urzeit
urzeit

Reputation: 2909

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?

Upvotes: 5

Views: 887

Answers (2)

Cody Gray
Cody Gray

Reputation: 244873

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.

Upvotes: 3

gnasher729
gnasher729

Reputation: 52602

What are you going to do if it is not available? Is your code supposed to compile and work? If not, drop the checking, use unsigned long long, and the compiler will tell you if it cannot handle it.

And if you want a macro that works on C99 compilers - well, that is pointless, since C99 requires unsigned long long.

Upvotes: 2

Related Questions