Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if uint64_t is defined

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?

like image 658
Nico Schlömer Avatar asked Jul 12 '14 10:07

Nico Schlömer


1 Answers

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.

like image 62
Grzegorz Szpetkowski Avatar answered Sep 22 '22 18:09

Grzegorz Szpetkowski