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?
It is specified in Paragraph 2.14.2 of the C++11 Standard:
[...]
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!");
}
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.)
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 ...
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.
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.