Integers greater than 4294967295 on 32-bit Windows

I am trying to deal with the basics of C ++ by creating a simple arithmetic calculator application. Right now I'm trying to figure out how to make it able to deal with integers greater than 4294967295 on 32-bit Windows. I know that the built-in Windows calculator is capable of this. What did I miss?

Please note that this application must be compiled with both the MSVC compiler and g ++ (MinGW / GCC).

Thanks.

+4
source share
4 answers

If you want to be compatible with gcc and msvc, use < stdint.h >. This is a source code compatible with both.

You'll probably need uint64_t for this. This will bring you up to $ 18,446,744,073,709,709,551,615.

There are also libraries so you can use integers larger than you also have memory.

+7
source

Use __ int64 to get 64-bit int calculations in Visual C ++ - not sure if GCC will like this.

You can create a header file that typedefs (say) MyInt64 matches the corresponding thing for each compiler. Then you can work internally with MyInt64 , and the compiled code will be correct for each purpose. This is a fairly standard way to support different target compilers on the same source code base.

afai can say long long will work fine for both, but I haven't used GCC, so YMMV is here for GCC info and here for Visual C ++.

+1
source

You can also create the Big Number class, which would basically preserve the value for several variables in one form or another.

0
source

There are different solutions, if 2 ^ 64 is enough for you, you can use the 64-bit integer type (they depend on the implementation, so search for your specific compiler). On the other hand, if you want to be able to process any number, you will have to use or implement the BigInteger type, which encapsulates it. Implementation is an interesting exercise ... basically use a smaller type vector, work with each subelement, and then merge and normalize the result.

0
source

All Articles