开发者

C++ variant for Java long?

开发者 https://www.devze.com 2023-01-07 07:02 出处:网络
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.

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++?

Ma开发者_如何学运维ybe with some tricks?

Thanks


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.


C++ has a long long type, with a length of 64 bits (on most platforms).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消