Reputation: 68877
Is there a C++ variant for the long
primitive data-type?
A C++ long
is only 4 bytes, while a Java long
is 8 bytes.
So: Is there a non-decimal primitive type with a size of 8 bytes in C++?
Maybe with some tricks?
Thanks
Upvotes: 2
Views: 6451
Reputation:
Since C++11, there are fixed width integer types in the <cstdint>
header.
In your scenario, you would want to use std::int64_t
or std::uint64_t
.
Because it is part of the C++11 language specification, platform and compiler compatibility should be guaranteed.
Upvotes: 2
Reputation: 346357
Microsoft Visual C++ defines an __int64
type that's equivalent to Java's long
. gcc has int64_t
. There's even a long long int
type defined in the ISO C99 standard, however according to the standard it's at least 64 bits wide, but could be wider.
But apart from the size, there's also endianness to consider. The Java standard mandates big endian, but with C, endianness is AFAIK always platform-dependant.
Upvotes: 4
Reputation: 3055
C++ has a long long
type, with a length of 64 bits (on most platforms).
Upvotes: 3