C++ Java long 的变体?
long
原始数据类型是否有 C++ 变体?
C++ long
仅 4 个字节,而 Java long
为 8 个字节。
那么:C++中是否存在大小为8字节的非十进制原始类型?
也许有一些技巧?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Microsoft Visual C++ 定义了一个
__int64
类型,它相当于 Java 的long
类型。 gcc 有int64_t
。 ISO C99 标准中甚至定义了long long int
类型,但根据该标准,它至少 64 位宽,但可能更宽。但除了大小之外,还需要考虑字节序。 Java 标准强制要求大字节序,但对于 C,字节序始终依赖于平台。
Microsoft Visual C++ defines an
__int64
type that's equivalent to Java'slong
. gcc hasint64_t
. There's even along 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++ 有一个
long long
类型,长度为 64 位(在大多数平台上)。C++ has a
long long
type, with a length of 64 bits (on most platforms).从 C++11 开始,
中有固定宽度整数类型 >
标头。在您的场景中,您可能需要使用
std::int64_t
或std::uint64_t
。因为它是C++11语言规范的一部分,所以应该保证平台和编译器的兼容性。
Since C++11, there are fixed width integer types in the
<cstdint>
header.In your scenario, you would want to use
std::int64_t
orstd::uint64_t
.Because it is part of the C++11 language specification, platform and compiler compatibility should be guaranteed.