[lex.icon] (original) (raw)
5 Lexical conventions [lex]
5.13 Literals [lex.literal]
5.13.2 Integer literals [lex.icon]
octal-digit: one of
0 1 2 3 4 5 6 7
nonzero-digit: one of
1 2 3 4 5 6 7 8 9
hexadecimal-prefix: one of
0x 0X
hexadecimal-digit: one of
0 1 2 3 4 5 6 7 8 9
a b c d e f
A B C D E F
unsigned-suffix: one of
u U
long-long-suffix: one of
ll LL
In an integer-literal, the sequence ofbinary-digits,octal-digits,digits, orhexadecimal-digit_s_is interpreted as a base N integer as shown in Table 7; the lexically first digit of the sequence of digits is the most significant.
[Note 1:
The prefix and any optional separating single quotes are ignored when determining the value.
β _end note_]
The hexadecimal-digits a through f and A through Fhave decimal values ten through fifteen.
[Example 1:
The number twelve can be written 12, 014,0XC, or 0b1100.
The integer-literals 1048576,1'048'576, 0X100000, 0x10'0000, and0'004'000'000 all have the same value.
β _end example_]
The type of an integer-literal is the first type in the list in Table 8corresponding to its optional integer-suffixin which its value can be represented.
Table 8 β Types of integer-literals [tab:lex.icon.type]
πinteger-suffix | decimal-literal | integer-literal other than decimal-literal |
---|---|---|
πnone | int | int |
π | long int | unsigned int |
π | long long int | long int |
π | unsigned long int | |
π | long long int | |
π | unsigned long long int | |
πu or U | unsigned int | unsigned int |
π | unsigned long int | unsigned long int |
π | unsigned long long int | unsigned long long int |
πl or L | long int | long int |
π | long long int | unsigned long int |
π | long long int | |
π | unsigned long long int | |
πBoth u or U | unsigned long int | unsigned long int |
πand l or L | unsigned long long int | unsigned long long int |
πll or LL | long long int | long long int |
π | unsigned long long int | |
πBoth u or U | unsigned long long int | unsigned long long int |
πand ll or LL | ||
πz or Z | the signed integer type corresponding | the signed integer type |
π | to stdβ::βsize_t ([support.types.layout]) | corresponding to stdβ::βsize_t |
π | stdβ::βsize_t | |
πBoth u or U | stdβ::βsize_t | stdβ::βsize_t |
πand z or Z |
Except for integer-literals containing a size-suffix, if the value of an integer-literalcannot be represented by any type in its list and an extended integer type ([basic.fundamental]) can represent its value, it may have that extended integer type.
If all of the types in the list for the integer-literalare signed, the extended integer type is signed.
If all of the types in the list for the integer-literalare unsigned, the extended integer type is unsigned.
If the list contains both signed and unsigned types, the extended integer type may be signed or unsigned.
If an integer-literalcannot be represented by any of the allowed types, the program is ill-formed.
[Note 2:
An integer-literal with a z or Z suffix is ill-formed if it cannot be represented by stdβ::βsize_t.
β _end note_]