ULL suffix on a numeric literal
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?
Solution 1:
From the gcc
manual:
ISO C99 supports data types for integers that are at least 64 bits wide ( . . . ) . To make an integer constant of type
long long int
, add the suffixLL
to the integer. To make an integer constant of typeunsigned long long int
, add the suffixULL
to the integer.
These suffixes have also been added to C++ in C++11, and were already supported long long (pun intended) before that as compiler extensions.
Solution 2:
Yes that's correct.
-
0x
prefix makes it a hexadecimal literal. -
ULL
suffix makes it typeunsigned long long
.
Solution 3:
I'm positing a new answer because I recognize that the current answers do not cite from a cross platform source. The c++11 standard dictates that a literal with U
/u
and LL
/ll
suffixes is a literal of type: unsigned long long int
[source]
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++11 and required to have a length of at least 64-bits.
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++11 marked 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++14 introduced order independent literal suffixes. Previously the
U
/u
suffix had to preceded any size suffix. But circa c++14 the 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