[lex.icon]

# 5 Lexical conventions [[lex]](./#lex)

## 5.13 Literals [[lex.literal]](lex.literal#lex.icon)

### 5.13.2 Integer literals [lex.icon]

[integer-literal:](#nt:integer-literal "5.13.2 Integer literals [lex.icon]")  
[*binary-literal*](#nt:binary-literal "5.13.2 Integer literals [lex.icon]") [*integer-suffix*](#nt:integer-suffix "5.13.2 Integer literals [lex.icon]")opt  
[*octal-literal*](#nt:octal-literal "5.13.2 Integer literals [lex.icon]") [*integer-suffix*](#nt:integer-suffix "5.13.2 Integer literals [lex.icon]")opt  
[*decimal-literal*](#nt:decimal-literal "5.13.2 Integer literals [lex.icon]") [*integer-suffix*](#nt:integer-suffix "5.13.2 Integer literals [lex.icon]")opt  
[*hexadecimal-literal*](#nt:hexadecimal-literal "5.13.2 Integer literals [lex.icon]") [*integer-suffix*](#nt:integer-suffix "5.13.2 Integer literals [lex.icon]")opt

[binary-literal:](#nt:binary-literal "5.13.2 Integer literals [lex.icon]")  
0b [*binary-digit*](#nt:binary-digit "5.13.2 Integer literals [lex.icon]")  
0B [*binary-digit*](#nt:binary-digit "5.13.2 Integer literals [lex.icon]")  
[*binary-literal*](#nt:binary-literal "5.13.2 Integer literals [lex.icon]") 'opt [*binary-digit*](#nt:binary-digit "5.13.2 Integer literals [lex.icon]")

[octal-literal:](#nt:octal-literal "5.13.2 Integer literals [lex.icon]")  
0  
[*octal-literal*](#nt:octal-literal "5.13.2 Integer literals [lex.icon]") 'opt [*octal-digit*](#nt:octal-digit "5.13.2 Integer literals [lex.icon]")

[decimal-literal:](#nt:decimal-literal "5.13.2 Integer literals [lex.icon]")  
[*nonzero-digit*](#nt:nonzero-digit "5.13.2 Integer literals [lex.icon]")  
[*decimal-literal*](#nt:decimal-literal "5.13.2 Integer literals [lex.icon]") 'opt [*digit*](lex.name#nt:digit "5.11 Identifiers [lex.name]")

[hexadecimal-literal:](#nt:hexadecimal-literal "5.13.2 Integer literals [lex.icon]")  
[*hexadecimal-prefix*](#nt:hexadecimal-prefix "5.13.2 Integer literals [lex.icon]") [*hexadecimal-digit-sequence*](#nt:hexadecimal-digit-sequence "5.13.2 Integer literals [lex.icon]")

[binary-digit:](#nt:binary-digit "5.13.2 Integer literals [lex.icon]") one of  
0 1

[octal-digit:](#nt:octal-digit "5.13.2 Integer literals [lex.icon]") one of  
0 1 2 3 4 5 6 7

[nonzero-digit:](#nt:nonzero-digit "5.13.2 Integer literals [lex.icon]") one of  
1 2 3 4 5 6 7 8 9

[hexadecimal-prefix:](#nt:hexadecimal-prefix "5.13.2 Integer literals [lex.icon]") one of  
0x 0X

[hexadecimal-digit-sequence:](#nt:hexadecimal-digit-sequence "5.13.2 Integer literals [lex.icon]")  
[*hexadecimal-digit*](#nt:hexadecimal-digit "5.13.2 Integer literals [lex.icon]")  
[*hexadecimal-digit-sequence*](#nt:hexadecimal-digit-sequence "5.13.2 Integer literals [lex.icon]") 'opt [*hexadecimal-digit*](#nt:hexadecimal-digit "5.13.2 Integer literals [lex.icon]")

[hexadecimal-digit:](#nt:hexadecimal-digit "5.13.2 Integer literals [lex.icon]") one of  
0 1 2 3 4 5 6 7 8 9  
a b c d e f  
A B C D E F

[integer-suffix:](#nt:integer-suffix "5.13.2 Integer literals [lex.icon]")  
[*unsigned-suffix*](#nt:unsigned-suffix "5.13.2 Integer literals [lex.icon]") [*long-suffix*](#nt:long-suffix "5.13.2 Integer literals [lex.icon]")opt   
[*unsigned-suffix*](#nt:unsigned-suffix "5.13.2 Integer literals [lex.icon]") [*long-long-suffix*](#nt:long-long-suffix "5.13.2 Integer literals [lex.icon]")opt   
[*unsigned-suffix*](#nt:unsigned-suffix "5.13.2 Integer literals [lex.icon]") [*size-suffix*](#nt:size-suffix "5.13.2 Integer literals [lex.icon]")opt   
[*long-suffix*](#nt:long-suffix "5.13.2 Integer literals [lex.icon]") [*unsigned-suffix*](#nt:unsigned-suffix "5.13.2 Integer literals [lex.icon]")opt   
[*long-long-suffix*](#nt:long-long-suffix "5.13.2 Integer literals [lex.icon]") [*unsigned-suffix*](#nt:unsigned-suffix "5.13.2 Integer literals [lex.icon]")opt   
[*size-suffix*](#nt:size-suffix "5.13.2 Integer literals [lex.icon]") [*unsigned-suffix*](#nt:unsigned-suffix "5.13.2 Integer literals [lex.icon]")opt

[unsigned-suffix:](#nt:unsigned-suffix "5.13.2 Integer literals [lex.icon]") one of  
u U

[long-suffix:](#nt:long-suffix "5.13.2 Integer literals [lex.icon]") one of  
l L

[long-long-suffix:](#nt:long-long-suffix "5.13.2 Integer literals [lex.icon]") one of  
ll LL

[size-suffix:](#nt:size-suffix "5.13.2 Integer literals [lex.icon]") one of  
z Z

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lex.tex#L1268)

In an [*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]"),
the sequence of[*binary-digit*](#nt:binary-digit "5.13.2 Integer literals [lex.icon]")*s*,[*octal-digit*](#nt:octal-digit "5.13.2 Integer literals [lex.icon]")*s*,[*digit*](lex.name#nt:digit "5.11 Identifiers [lex.name]")*s*, or[*hexadecimal-digit*](#nt:hexadecimal-digit "5.13.2 Integer literals [lex.icon]")*s* is interpreted as a base N integer as shown in Table [7](#tab:lex.icon.base "Table 7: Base of integer-literals");
the lexically first digit of the sequence of digits is the most significant[.](#1.sentence-1)

[*Note [1](#note-1)*:

The prefix and any optional separating single quotes are ignored
when determining the value[.](#1.sentence-2)

â *end note*]

Table [7](#tab:lex.icon.base) — Base of [*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]")*s* [[tab:lex.icon.base]](./tab:lex.icon.base)  

| [ð](#tab:lex.icon.base-row-1)<br>**Kind of [*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]")** | **base N** |
| --- | --- |
| [ð](#tab:lex.icon.base-row-2)<br>[*binary-literal*](#nt:binary-literal "5.13.2 Integer literals [lex.icon]") | 2 |
| [ð](#tab:lex.icon.base-row-3)<br>[*octal-literal*](#nt:octal-literal "5.13.2 Integer literals [lex.icon]") | 8 |
| [ð](#tab:lex.icon.base-row-4)<br>[*decimal-literal*](#nt:decimal-literal "5.13.2 Integer literals [lex.icon]") | 10 |
| [ð](#tab:lex.icon.base-row-5)<br>[*hexadecimal-literal*](#nt:hexadecimal-literal "5.13.2 Integer literals [lex.icon]") | 16 |

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lex.tex#L1297)

The [*hexadecimal-digit*](#nt:hexadecimal-digit "5.13.2 Integer literals [lex.icon]")*s*a through f and A through F have decimal values ten through fifteen[.](#2.sentence-1)

[*Example [1](#example-1)*:

The number twelve can be written 12, 014,0XC, or 0b1100[.](#2.sentence-2)

The [*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]")*s* 1048576,1'048'576, 0X100000, 0x10'0000, and0'004'000'000 all have the same value[.](#2.sentence-3)

â *end example*]

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lex.tex#L1308)

The type of an [*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]") is
the first type in the list in Table [8](#tab:lex.icon.type "Table 8: Types of integer-literals") corresponding to its optional [*integer-suffix*](#nt:integer-suffix "5.13.2 Integer literals [lex.icon]") in which its value can be represented[.](#3.sentence-1)

Table [8](#tab:lex.icon.type) — Types of [*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]")*s* [[tab:lex.icon.type]](./tab:lex.icon.type)  

| [ð](#tab:lex.icon.type-row-1)<br>**[*integer-suffix*](#nt:integer-suffix "5.13.2 Integer literals [lex.icon]")** | **[*decimal-literal*](#nt:decimal-literal "5.13.2 Integer literals [lex.icon]")** | **[*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]") other than [*decimal-literal*](#nt:decimal-literal "5.13.2 Integer literals [lex.icon]")** |
| --- | --- | --- |
| [ð](#tab:lex.icon.type-row-2)<br>none | int | int |
| [ð](#tab:lex.icon.type-row-3) | long int | unsigned int |
| [ð](#tab:lex.icon.type-row-4) | long long int | long int |
| [ð](#tab:lex.icon.type-row-5) |  | unsigned long int |
| [ð](#tab:lex.icon.type-row-6) |  | long long int |
| [ð](#tab:lex.icon.type-row-7) |  | unsigned long long int |
| [ð](#tab:lex.icon.type-row-8)<br>u or U | unsigned int | unsigned int |
| [ð](#tab:lex.icon.type-row-9) | unsigned long int | unsigned long int |
| [ð](#tab:lex.icon.type-row-10) | unsigned long long int | unsigned long long int |
| [ð](#tab:lex.icon.type-row-11)<br>l or L | long int | long int |
| [ð](#tab:lex.icon.type-row-12) | long long int | unsigned long int |
| [ð](#tab:lex.icon.type-row-13) |  | long long int |
| [ð](#tab:lex.icon.type-row-14) |  | unsigned long long int |
| [ð](#tab:lex.icon.type-row-15)<br>Both u or U | unsigned long int | unsigned long int |
| [ð](#tab:lex.icon.type-row-16)<br>and l or L | unsigned long long int | unsigned long long int |
| [ð](#tab:lex.icon.type-row-17)<br>ll or LL | long long int | long long int |
| [ð](#tab:lex.icon.type-row-18) |  | unsigned long long int |
| [ð](#tab:lex.icon.type-row-19)<br>Both u or U | unsigned long long int | unsigned long long int |
| [ð](#tab:lex.icon.type-row-20)<br>and ll or LL |  |  |
| [ð](#tab:lex.icon.type-row-21)<br>z or Z | the signed integer type corresponding | the signed integer type |
| [ð](#tab:lex.icon.type-row-22) | to std​::​size_t ([[support.types.layout]](support.types.layout "17.2.4 Sizes, alignments, and offsets")) | corresponding to std​::​size_t |
| [ð](#tab:lex.icon.type-row-23) |  | std​::​size_t |
| [ð](#tab:lex.icon.type-row-24)<br>Both u or U | std​::​size_t | std​::​size_t |
| [ð](#tab:lex.icon.type-row-25)<br>and z or Z |  |  |

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/lex.tex#L1399)

Except for [*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]")*s* containing
a [*size-suffix*](#nt:size-suffix "5.13.2 Integer literals [lex.icon]"),
if the value of an [*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]") cannot be represented by any type in its list and
an extended integer type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types")) can represent its value,
it may have that extended integer type[.](#4.sentence-1)

If all of the types in the list for the [*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]") are signed,
the extended integer type is signed[.](#4.sentence-2)

If all of the types in the list for the [*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]") are unsigned,
the extended integer type is unsigned[.](#4.sentence-3)

If the list contains both signed and unsigned types,
the extended integer type may be signed or unsigned[.](#4.sentence-4)

If an [*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]") cannot be represented by any of the allowed types,
the program is ill-formed[.](#4.sentence-5)

[*Note [2](#note-2)*:

An [*integer-literal*](#nt:integer-literal "5.13.2 Integer literals [lex.icon]") with a z or Z suffix
is ill-formed if it cannot be represented by std​::​size_t[.](#4.sentence-6)

â *end note*]
