11

Is LL defined anywhere in the standard (hard term to come by)?

ideone accepts the code

int main()
{
    std::cout << sizeof(0LL) << std::endl;
    std::cout << sizeof(0);
}

and prints

8
4

But what does it mean?

phuclv
  • 37,963
  • 15
  • 156
  • 475
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625

4 Answers4

11

It is specified in Paragraph 2.14.2 of the C++11 Standard:

2.14.2 Integer literals

[...]

long-long-suffix: one of

ll LL

Paragraph 2.14.2/2, and in particular Table 6, goes on specifying the meaning of the suffix for decimal, octal, and hexadecimal constants, and the types they are given.

Since 0 is an octal literal, the type of 0LL is long long int:

#include <type_traits>

int main()
{
    // Won't fire
    static_assert(std::is_same<decltype(0LL), long long int>::value, "Ouch!");
}
Andy Prowl
  • 124,023
  • 23
  • 387
  • 451
4

LL is the suffix for long-long, which is 64-bit on most (all?) C/C++ implementations. So 0LL is a 64-bit literal with the value of 0.

This is similar to L being the suffix for a long literal, which on most 32- and 64-bit C/C++ implementations is the same size as a non-long int. (On 16-bit implementations, the size of int is usually 16 bits, and so the L suffix would indicate a 32-bit integer literal in contrast to the default of 16 bits.)

cdhowie
  • 158,093
  • 24
  • 286
  • 300
4

0LL is an integer literal. It's suffix is LL which determines the possible set of types that it might have. For a decimal constant, the type will be long long int. For an octal or hexadecimal constant, the type will be long long int or unsigned long long int if necessary. In the case of 0LL, the literal is of type long long int.

The type of an integer literal is the first of the corresponding list in Table 6 in which its value can be represented.

Table 6 - Types of integer constants

Suffix     Decimal constants    Octal or hexadecimal constant
...
ll or LL   long long int        long long int
                                unsigned long long int
...
Community
  • 1
  • 1
Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
  • When do octal and hexadecimal literals become unsigned "if necessary", except when using another suffix that's not mentioned here? – unwind Mar 22 '13 at 16:19
  • @unwind When the value doesn't fit in a `long long int` but does fit inside an `unsigned long long int`. It is only considered if it doesn't fit inside a `long long int`. – Joseph Mansfield Mar 22 '13 at 16:19
  • @unwind When they don't fit into the signed type. Say, ints are 16-bit. 0x7fff fits into int. 0x8000 doesn't fit into int, but fits into unsigned int. – Alexey Frunze Mar 22 '13 at 16:20
0

We will begin with an example:

std::cout << 2LL << endl;

This outcome will be 2, and this happens, because depending on the data size, and to properly fix it, we want in some situations, use a 2 as long long, and this is exactly what happens. The output given is of type long long, representing the constant int 2.

Another suffixes are (from geeks):

unsigned int: character u or U at the end of integer constant.

long int: character l or L at the end of integer constant.

unsigned long int: character ul or UL at the end of integer constant.

long long int: character ll or LL at the end of integer constant. unsigned long long int: character ull or ULL at the end of integer constant.