C++ 数字文字上的 ULL 后缀
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8809292/
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
ULL suffix on a numeric literal
提问by aneccodeal
I've run across some code like this:
我遇到过一些这样的代码:
line += addr & 0x3fULL;
Obviously, 'U' and 'L' are not hex digits. I'm guessing that the 'ULL' at the end of that hex numeric literal means "Unsigned Long Long" - am I correct? (this sort of thing is very difficult to google) if so then this is some sort of suffix modifier on the number?
显然,'U' 和 'L' 不是十六进制数字。我猜那个十六进制数字文字末尾的“ULL”表示“Unsigned Long Long”——我说得对吗?(这种事情很难用谷歌搜索)如果是这样,那么这是数字上的某种后缀修饰符吗?
采纳答案by NPE
From the gcc
manual:
从gcc
手册:
ISO C99 supports data types for integers that are at least 64 bits wide, and as an extension GCC supports them in C90 mode and in C++. Simply write
long long int
for a signed integer, orunsigned long long int
for an unsigned integer. To make an integer constant of typelong long int
, add the suffixLL
to the integer. To make an integer constant of typeunsigned long long int
, add the suffixULL
to the integer.
ISO C99 支持至少 64 位宽的整数数据类型,作为扩展,GCC 在 C90 模式和 C++ 中支持它们。只需
long long int
为有符号整数或unsigned long long int
无符号整数写入即可。要生成类型为 的整数常量long long int
,请将后缀添加LL
到整数。要生成类型为 的整数常量unsigned long long int
,请将后缀添加ULL
到整数。
回答by Mysticial
Yes that's correct.
对,那是正确的。
0x
prefix makes it a hexadecimal literal.ULL
suffix makes it typeunsigned long long
.
0x
前缀使其成为十六进制文字。ULL
后缀使它键入unsigned long long
.
回答by Jonathan Mee
I'm positing a new answer because I recognize that the current answers do not cite from a cross platform source. The c++11standard dictates that a literal with U
/u
and LL
/ll
suffixes is a literal of type: unsigned long long int
[source]
我提出了一个新答案,因为我认识到当前的答案并未引用跨平台来源。在C ++ 11条标准规定文字与U
/u
和LL
/ll
后缀是一种类型的文字:unsigned long long int
[源]
U
/u
is the C/C++ suffix for an unsigned integer.LL
/ll
is the C/C++ suffix for a long long
integer which is a new type in C++11and required to have a length of at least 64-bits.
U
/u
是无符号整数的 C/C++ 后缀。LL
/ll
是long long
整数的 C/C++ 后缀,它是C++11 中的一种新类型,要求长度至少为 64 位。
Notes:
笔记:
- The keyword
int
may be omitted if any modifiers are used,unsigned long long
for example. So this will defineone
as anunsigned long long int
, and any number assigned to it will bestatic_cast
tounsigned long long int
:unsigned long long one = 1
- c++11marked the advent of
auto
. Which sets the variable type to the type assigned to it on declaration. For example, because2ULL
is anunsigned long long int
literaltwo
will be defined as anunsigned long long int
:auto two = 2ULL
- c++14introduced order independent literal suffixes. Previously the
U
/u
suffix had to preceded any size suffix. But circa c++14the suffixes are accepted in either order, so now since3LLU
is anunsigned long long int
literalthree
will be defined as anunsigned long long int
:auto three = 3LLU
- 例如
int
,如果使用了任何修饰符,则可以省略关键字unsigned long long
。因此,这将定义one
为unsigned long long int
,并分配给它的任何数量将static_cast
到unsigned long long int
:unsigned long long one = 1
- c++11标志着
auto
. 它将变量类型设置为声明时分配给它的类型。例如,因为2ULL
是unsigned long long int
文字two
将被定义为unsigned long long int
:auto two = 2ULL
- c++14引入了与顺序无关的文字后缀。以前
U
/u
后缀必须位于任何大小后缀之前。但是大约c++14后缀以任一顺序接受,所以现在因为3LLU
是unsigned long long int
文字three
将被定义为unsigned long long int
:auto three = 3LLU