2.13.1 - [lex.icon] - 【词法.整数常量】

请不要转载本文;请不要以任何形式重新出版,发布本文;请在下载本文 24 小时内将其删除;禁止将本文用于商业目的。

2 Lexical conventions [lex]

2.13 Literals [lex.literal]
2.13.1 Integer literals [lex.icon]

 

2 词法约定 【词法】

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

 

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

    decimal-literal:
        nonzero-digit
        decimal-literal digit

    octal-literal:
        0
        octal-literal octal-digit

    hexadecimal-literal:
        0x hexadecimal-digit
        0X hexadecimal-digit
        hexadecimal-literal 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

    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

    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. ]

 

整数文字量是不含有句点或指数部分的数字序列。整数文字量可能包含指定其基数的前缀或指定其类型的后缀。数字序列词法的第一个数字最重要。十进制整数文字量开始于不是 0 的数字并由十进制数字序列构成。八进制整数文字量开始于数字 0 并由八进制数字序列构成。22) 十六进制整数文字量开始于 0x0X 并由十六进制数字序列构成,十六进制数字包括十进制数字和用以表示十进制数值从十到十五的,从 af 以及从 AF 的字母。【例:数值十二可以被写成 12014,或 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.

 

整数文字量的类型以来于其形式,值,以及后缀。如果它是十进制的并且没有后缀,则其具有下列能够表达其值的第一个类型:intlong int;如果其值不能被 long int 表达,其行为是未定义的。如果它是八进制或十六进制并且没有后缀,则其具有下列能够表达其值的第一个类型:intunsigned intlong intunsigned long int。如果它具有后缀 uU,则其具有下列能够表达其值的第一个类型:unsigned intunsigned long int。如果它具有后缀 lL,则其具有下列能够表达其值的第一个类型:long intunsigned long int。如果它具有后缀 ulluuLLuUllUUL,或 LU, 则其具有类型 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值