check if uint64_t is defined

c++, preprocessor-directive, types

Solution

I think that reasonable approach is to check if associated macro `UINT64_MAX` is defined, e.g.

#include <cstdint> /* don't forget to include */

...

#ifdef UINT64_MAX
    ...
#endif

AFAIK you can't check directly if some type synonym is defined. According to C99, 7.18.2 Limits of specified-width integer types (don't have copy of C++ standard to confirm, emphasis mine):

The following object-like macros specify the minimum and maximum limits of the types declared in `<stdint.h>`. Each macro name corresponds to a similar type name in 7.18.1.

Problem

The type `uint64_t` is not guaranteed to be defined on 32-bit platforms, and code like ``` int main() { uint64_t i = 0; } ``` may result in compilation errors of the type `incomplete type`. Is there a preprocessor directive to check if `uint64_t` is present? Any other way for checking if the type is defined?

Original source