### 2 词法约定 【词法】

#### 2.13.1 整数文字量 【词法.整数常量】

integer-literal:
decimal-literal integer-suffixopt
octal-literal integer-suffixopt

decimal-literal:
nonzero-digit
decimal-literal digit

octal-literal:
0
octal-literal octal-digit

0x hexadecimal-digit
0X hexadecimal-digit

nonzero-digit: one of
1 2 3 4 5 6 7 8 9

octal-digit: one of
0 1 2 3 4 5 6 7

0 1 2 3 4 5 6 7 8 9
a b c d e f
A B C D E F

integer-suffix:
unsigned-suffix long-suffixopt
long-suffix unsigned-suffixopt

unsigned-suffix: one if
u U

long-suffix: one of
l L

整数-文字量:
十进制-文字量 整数-后缀opt
八进制-文字量 整数-后缀opt
十六进制-文字量 整数-后缀opt

十进制-文字量:
非零-数字
十进制-文字量 数字

八进制-文字量:
0
八进制-文字量 八进制-数字

十六进制-文字量:
0x 十六进制-数字
0X 十六进制-数字
十六进制-文字量 十六进制-数字

非零-数字: 下列之一
1 2 3 4 5 6 7 8 9

八进制-数字: 下列之一
0 1 2 3 4 5 6 7

十六进制-数字: 下列之一
0 1 2 3 4 5 6 7 8 9
a b c d e f
A B C D E F

整数-后缀:
unsigned-后缀 long-后缀opt
long-后缀 unsigned-后缀opt

unsigned-后缀: 下列之一
u U

long-后缀: 下列之一
l L

An integer literal is a sequence of digits that has no period or exponent part. An integer literal may have a prefix that specifies its base and a suffix that specifies its type. The lexically first digit of the sequence of digits is the most significant. A decimal integer literal (base ten) begins with a digit other than 0 and consists of a sequence of decimal digits. An octal integer literal (base eight) begins with the digit 0 and consists of a sequence of octal digits.22) A hexadecimal integer literal (base sixteen) begins with 0x or 0X and consists of a sequence of hexadecimal digits, which include the decimal digits and the letters a through f and A through F with decimal values ten through fifteen. [Example: the number twelve can be written 12, 014, or 0XC. ]

The type of an integer literal depends on its form, value, and suffix. If it is decimal and has no suffix, it has the first of these types in which its value can be represented: int, long int; if the value cannot be represented as a long int, the behavior is undefined. If it is octal or hexadecimal and has no suffix, it has the first of these types in which its value can be represented: int, unsigned int, long int, unsigned long int. If it is suffixed by u or U, its type is the first of these types in which its value can be represented: unsigned int, unsigned long int. If it is suffixed by l or L, its type is the first of these types in which its value can be represented: long int, unsigned long int. If it is suffixed by ul, lu, uL, Lu, Ul, lU, UL, or LU, its type is unsigned long int.

A program is ill-formed if one of its translation units contains an integer literal that cannot be represented by any of the allowed types.

22) The digits 8 and 9 are not octal digits.

22) 数字 89 不是八进制数字。

PREV [lex.literal] | NEXT [lex.ccon] 上一页 【词法.文字量】 | 下一页 【词法.字符常量】

0 0