Alex Rivera | Logout

How to do portable 64 bit arithmetic, without compiler warnings

Asked 2010-10-25T18:28:08.490
17

I occasionally use 64 bit arithmetic in an open source C++ library of mine. I discovered that long long serves my purpose quite nicely. Even some 10 year old solaris box could compile it. And it works without messing around with #defines on Windows too.

Now the issue is I get complaints from my users because they compile with GCC -pedantic settings, and GCC insists on issuing warnings that long long is not part of the C++ standard. This is probably right, but I am not too interested in the C++ standard per se, I just want my code to work on as many compilers as reasonably possible.

So my question is twofold:

  • can anyone name actual C++ compilers that don't support 64 bit long long's?
  • is there a way to make GCC compile 64 bit arithmetic (on 32 bit platform) without compiler warnings? (stdint.h does not help, as it also depends on long long)

P.S.

If there are platforms where long longs become 128 bit or bigger, that is interesting, but not a problem for me.

Edit
Report

2 Answers

5

You can silence the warning with -Wno-long-long (make sure it comes after -pedantic). 64-bit integers are required by C99 and I think also C++0x so compilers that don't have them are getting rare nowadays.

answered 2010-10-25T18:37:20.527
-1

You could replace your use of long long with one of the many C++ bigint libraries. I'm sure some of them avoid this compiler error. Personally, I'd rather stick with the error.

answered 2010-10-25T19:31:12.620

Your Answer