Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ cross platform way to define 64bit unsigned integer

Right now I'm working on a project that extensively uses 64bit unsigned integers in many parts of the code. So far we have only been compiling with gcc 4.6 but we are now porting some code to windows. It's crucial that these unsigned ints are 64bits wide. It has been suggested that we could use long long but it's not good if long long happens to be bigger than 64bits, we actually want to have a guarantee that it will be 64 bits and writing something like static_assert(sizeof(long long) == 8) seems to be a bit of a code smell.

What is the best way to define something like uint64 that will compile across both gcc and msvc without needing to have different code syntax used everywhere?

like image 687
shuttle87 Avatar asked Dec 02 '22 23:12

shuttle87


1 Answers

What about including cstdint and using std::uint64_t?

like image 128
Inbae Jeong Avatar answered Dec 15 '22 14:12

Inbae Jeong