C++ unsigned long long 是多少字节?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5836329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 18:58:47  来源:igfitidea点击:

How many bytes is unsigned long long?

c++

提问by Dushant

How many bytes is unsigned long long? Is it the same as unsigned long long int?

有多少字节unsigned long long?是一样的unsigned long long int吗?

回答by Fred Foo

Executive summary: it's 64 bits, or larger.

执行摘要:它是 64 位或更大。

unsigned long longis the same as unsigned long long int. Its size is platform-dependent, but guaranteed by the C standard (ISO C99) to be at least 64 bits. There was no long longin C89, but apparently even MSVC supports it, so it's quite portable.

unsigned long long与 相同unsigned long long int。它的大小取决于平台,但由 C 标准 (ISO C99) 保证至少为 64 位。long longC89中没有,但显然即使 MSVC 也支持它,因此它非常便携。

In the current C++ standard (issued in 2003), there is no long long, though many compilers support it as an extension. The upcoming C++0x standard will support it and its size will be the same as in C, so at least 64 bits.

在当前的 C++ 标准(2003 年发布)中long long,虽然许多编译器支持它作为扩展,但没有. 即将推出的 C++0x 标准将支持它,其大小将与 C 中的相同,因此至少为 64 位。

You can get the exact size, in bytes (8 bits on typical platforms) with the expression sizeof(unsigned long long). If you want exactly 64 bits, use uint64_t, which is defined in the header <stdint.h>along with a bunch of related types (available in C99, C++11 and some current C++ compilers).

您可以使用表达式获得确切的大小,以字节为单位(在典型平台上为 8 位)sizeof(unsigned long long)。如果您想要正好 64 位,请使用uint64_t,它在标头中<stdint.h>与一堆相关类型一起定义(在 C99、C++11 和一些当前的 C++ 编译器中可用)。

回答by Ernest Friedman-Hill

The beauty of C++, like C, is that the sized of these things are implementation-defined, so there's no correct answer without your specifying the compiler you're using. Are those two the same? Yes. "long long" is a synonym for "long long int", for any compiler that will accept both.

C++ 和 C 一样的美妙之处在于这些东西的大小是实现定义的,所以如果不指定你正在使用的编译器,就没有正确的答案。这两个是一样的吗?是的。“long long”是“long long int”的同义词,对于任何接受两者的编译器。

回答by Michael Burr

It must be at least 64 bits. Other than that it's implementation defined.

它必须至少为 64 位。除此之外,它是实现定义的。

Strictly speaking, unsigned long longisn't standard in C++ until the C++0x standard. unsigned long longis a 'simple-type-specifier' for the type unsigned long long int(so they're synonyms).

严格来说,unsigned long long直到 C++0x 标准才成为 C++ 的标准。 unsigned long long是类型的“简单类型说明符” unsigned long long int(因此它们是同义词)。

The long longset of types is also in C99 and was a common extension to C++ compilers even before being standardized.

long long组类型也在 C99 中,甚至在标准化之前就是 C++ 编译器的通用扩展。

回答by Alessandro Jacopson

Use the operator sizeof, it will give you the size of a type expressed in byte. One byte is eight bits. See the following program:

使用 operator sizeof,它将为您提供以字节表示的类型的大小。一个字节是八位。请参阅以下程序:

#include <iostream>

int main(int,char**)
{
 std::cout << "unsigned long long " << sizeof(unsigned long long) << "\n";
 std::cout << "unsigned long long int " << sizeof(unsigned long long int) << "\n";
 return 0;
}