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 gccmanual:
从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 intfor a signed integer, orunsigned long long intfor an unsigned integer. To make an integer constant of typelong long int, add the suffixLLto the integer. To make an integer constant of typeunsigned long long int, add the suffixULLto 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.
对,那是正确的。
0xprefix makes it a hexadecimal literal.ULLsuffix 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/uand LL/llsuffixes is a literal of type: unsigned long long int[source]
我提出了一个新答案,因为我认识到当前的答案并未引用跨平台来源。在C ++ 11条标准规定文字与U/u和LL/ll后缀是一种类型的文字:unsigned long long int[源]
U/uis the C/C++ suffix for an unsigned integer.LL/llis the C/C++ suffix for a long longinteger 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
intmay be omitted if any modifiers are used,unsigned long longfor example. So this will defineoneas anunsigned long long int, and any number assigned to it will bestatic_casttounsigned 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, because2ULLis anunsigned long long intliteraltwowill be defined as anunsigned long long int:auto two = 2ULL - c++14introduced order independent literal suffixes. Previously the
U/usuffix had to preceded any size suffix. But circa c++14the suffixes are accepted in either order, so now since3LLUis anunsigned long long intliteralthreewill 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

