91

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?

aneccodeal
  • 8,531
  • 7
  • 45
  • 74
  • 4
    C: [N1570](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) 6.4.4.1. C++: [N4700](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4700.pdf) 5.13.2 [lex.icon]. In both languages, the suffix is case-insensitive (except that `lL` and `Ll` are not permitted) and the `LL` and `U` are specified separately, so you can have any of `ull`, `uLL`, `Ull`, `ULL`, `llu`, `llU`, `LLu`, `LLU`. – Keith Thompson Dec 28 '17 at 03:45
  • Ping @TonyTannous. – jww Jul 16 '18 at 20:47
  • Does this answer your question? [What do 0LL or 0x0UL mean?](https://stackoverflow.com/questions/7036056/what-do-0ll-or-0x0ul-mean) – phuclv Sep 03 '20 at 15:10
  • It can be essential when manipulating uint64_t values. For example: my_var |= (1ull << bit_pos) may not give the expected result when bit_pos is more than 32 on some compilers, without the 'ull' suffix – Martin CR Apr 04 '23 at 13:52

3 Answers3

92

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.

FrancoVS
  • 262
  • 1
  • 7
NPE
  • 486,780
  • 108
  • 951
  • 1,012
33

Yes that's correct.

  • 0x prefix makes it a hexadecimal literal.
  • ULL suffix makes it type unsigned long long.
Saurav Sahu
  • 13,038
  • 6
  • 64
  • 79
Mysticial
  • 464,885
  • 45
  • 335
  • 332
  • I suppose it makes the type *at least* that, but since it's the largest available type, that's probably the same thing. – Kerrek SB Jan 10 '12 at 19:29
  • You're right. I just tested it with `long long x = 0xfffffffffffful;` on Windows and it doesn't truncate - no warnings either. – Mysticial Jan 10 '12 at 19:34
  • 1
    All literals only specify the *minimal* desired width, with the absolute minimum being `int`. But any literal has a type that supports it, if any... – Kerrek SB Jan 10 '12 at 19:37
15

I'm positing a new answer because I recognize that the current answers do not cite from a cross platform source. The 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:

  1. The keyword int may be omitted if any modifiers are used, unsigned long long for example. So this will define one as an unsigned long long int, and any number assigned to it will be static_cast to unsigned long long int: unsigned long long one = 1
  2. marked the advent of auto. Which sets the variable type to the type assigned to it on declaration. For example, because 2ULL is an unsigned long long int literal two will be defined as an unsigned long long int: auto two = 2ULL
  3. introduced order independent literal suffixes. Previously the U/u suffix had to preceded any size suffix. But circa the suffixes are accepted in either order, so now since 3LLU is an unsigned long long int literal three will be defined as an unsigned long long int: auto three = 3LLU
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
  • 3
    Because my mind works that way (but I don't have C++14 to hand): I presume C++14 doesn't allow `13LUL`? – TripeHound Feb 16 '16 at 13:28
  • @TripeHound http://ideone.com has C++14 and it does not allow an LUL suffix: http://ideone.com/AWmW8H This seems to match the intent of: http://en.cppreference.com/w/cpp/language/integer_literal#Explanation – Jonathan Mee Feb 16 '16 at 13:33