Search code examples
c++typesportabilityint64long-long

64 bit integers and older C++ compilers


I want to use 64 bit integers in my C++ code. I understand I can either #include <cstdint> and then declare a uint64_t or use unsigned long long (or the equivalent for signed versions).

However, it appears that support for this was not added until C++11 and I would like my code to be compatible with compilers that don't have full C++11 support.

What is a good portable way to support 64 bit integers in C++?


Solution

  • uint64_t is:

    Optional: These typedefs are not defined if no types with such characteristics exist.

    as you can read in the ref.


    From Should I use long long or int64_t for portable code?:

    The types long long and unsigned long long are standard C and standard C++ types each with at least 64 bits. All compilers I'm aware of provide these types, except possibly when in a -pedantic mode but in this case int64_t or uint64_t won't be available with pre-C++ 2011 compilers, either. "


    What date did g++/clang support long long/int64_t from?

    Since GCC 4.3 (aka March 5, 2008).

    As David Álvarez mentioned.