ULL suffix on a numeric literal
C++CC++ Problem Overview
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?
C++ Solutions
Solution 1 - C++
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 suffix LL
to the integer. To make an integer constant of type unsigned long long int
, add the suffix ULL
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 - C++
Yes that's correct.
0x
prefix makes it a hexadecimal literal.ULL
suffix makes it typeunsigned long long
.
Solution 3 - C++
I'm positing a new answer because I recognize that the current answers do not cite from a cross platform source. The [tag: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
- [tag: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
- [tag:C++14] introduced order independent literal suffixes. Previously the
U
/u
suffix had to preceded any size suffix. But circa [tag: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