Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integers greater than 4294967295 on 32-bit Windows

Tags:

c++

integer

I'm trying to get to grips with C++ basics by building a simple arithmetic calculator application. Right now I'm trying to figure out how to make it capable of dealing with integers greater than 4294967295 on 32-bit Windows. I know that Windows' integrated Calculator is capable of this. What have I missed?

Note that this application should be compilable with both MSVC compiler and g++ (MinGW/GCC).

Thank you.

like image 660
Ken Maelstrom Avatar asked Feb 24 '23 05:02

Ken Maelstrom


2 Answers

If you want to be both gcc and msvc compatible use <stdint.h>. It's source code compatible with both.

You probably want uint64_t for this. It will get you up to 18,446,744,073,709,551,615.

There are also libraries to get you up to integers as large as you have memory to handle as well.

like image 176
Jay Avatar answered Mar 07 '23 12:03

Jay


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

You could create a header file that typedefs (say) MyInt64 to the appropriate thing for each compiler. Then you can work internally with MyInt64, and the compiled code will be correct for each target. This is a pretty standard way of supporting different target compilers on one source codebase.

afai can tell, long long would work OK for both, but I have not used GCC so YMMV - see here for GCC info and here for Visual C++.

like image 28
Steve Townsend Avatar answered Mar 07 '23 13:03

Steve Townsend