1

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 (e.g. 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?

Craig McQueen
  • 41,871
  • 30
  • 130
  • 181
  • What is your concern? Whether you should use `int64_t` by default? or whether you can use `int64_t` (or equivalent) in parts of your library? There are platforms that have innefficient 64bit integer types, and while code can be made compile you might not want to cater for those systems... – David Rodríguez - dribeas Oct 16 '13 at 01:27
  • Comeau is probably the place to look to find C++ compilers for funny platforms (including embedded systems). – Steve Jessop Oct 16 '13 at 01:37
  • "cross-platform" is a relative term. You should really define the platforms which you want to support, then you can accurately make decisions about what you can and cannot do. You have zero chance of covering them all. – Benjamin Lindley Oct 16 '13 at 02:19
  • 2
    It's a fairly specific question I'm asking. I realise it's hard to prove a negative (there are _no_ platforms lacking capability XYZ), but I hope that if anyone _does_ know of a platform where the C++ compiler doesn't have 64-bit integers, then they can say so here. – Craig McQueen Oct 16 '13 at 02:39

1 Answers1

1

This is an incomplete answer at this stage, but it's something...

Boost C++ Libraries

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

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.

Community
  • 1
  • 1
Craig McQueen
  • 41,871
  • 30
  • 130
  • 181
  • 2
    `BOOST_HAS_INT64_T` is a red herring: it is only found inside one header, where it's unconditionally being defined immediately before being used. It is by definition _always_ defined in all sources that "depend" on it. – sehe Oct 17 '13 at 07:25