I'm intending to write a C++ library that I want to be cross-platform. I'm just wondering if I would have to allow for platforms that lack any 64-bit integer types.
I know that there are 8- or 16-bit embedded systems with C compilers that have 32-bit integers but lack 64-bit integers (eg MSP430, at least historically), but is that true for any C++ compilers for such systems?
Context: I'm actually wanting to port a simple pseudo-random number generator C library of mine to C++. The C library mainly deals with 32-bit integers, but has some optional 64-bit API. Also the 32-bit code can do some internal calculations using 64-bit implementations (which are very simple), or alternatively using a 32-bit-only implementations (which are more complicated). The C headers have #ifdef UINT64_C
to enable/disable the 64-bit APIs. The C files have #ifdef UINT64_C
to select between 64-bit or 32-bit-only implementations of some functions. So, do I have to do the same for a C++ library, or is it a safe assumption that uint64_t
is always available?
This is an incomplete answer at this stage, but it's something...
I wondered what the Boost C++ libraries do about 64-bit, since they aim to be a set of high-quality multi-platform libraries. Looking through the code, I stumbled across
BOOST_HAS_LONG_LONG
BOOST_HAS_INT64_T
BOOST_HAS_MS_INT64
That indicates that the Boost libraries try to make allowances for platforms lacking long long
and/or uint64_t
, and maybe having a Microsoft specific __int64
type.
I want to investigate this in more detail. It would be good to find Boost documentation that explains all that.
C++11 defines long long
as at least 64 bits . C99 had already done so. So any compilers targeting C99 and/or C++11 should support 64-bit integer types. See this other question for some background.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.