Is there any way to set C++ long type size with 8 bytes (x64)?

1.3k views Asked by At

GCC compiles program using sizeof(long)=8 and Visual Studio has sizeof(long)=4. How to set sizeof(long) to 8 bytes on Winows x64?

2

There are 2 answers

2
Cory Kramer On BEST ANSWER

The actual size of long isn't specified to be an exact number of bytes, only the range of values that it must be able to represent. You could however use fixed width integers

std::int64_t

This, along with other fixed width integer types, are available in <cstdint>

0
Dan On

It's a common migration issue:https://msdn.microsoft.com/en-us/library/3b2e7499.aspx. As said before, the spec doesn't say specifically what size a long is and done platforms will be 4 and sone 8.