2.13.2 - [lex.ccon] - 【词法.字符常量】

博客围绕词法中的常量常量展开,但内容主要是版权声明,未涉及信息技术关键信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

2 Lexical conventions [lex]

2.13 Literals [lex.literal]
2.13.2 Character literals [lex.ccon]

 

2 词法约定 【词法】

2.13 文字量 【词法.文字量】
2.13.2 字符文字量 【词法.字符常量】

 

    character-literal:
        'c-char-sequence'
        L'c-char-sequence'

    c-char-sequence:
        c-char
        c-char-sequence c-char

    c-char:
        any member of the source character set except
            the single-quote ', backslash /, or new-line character
        escape-sequence
        universal-character-name

    escape-sequence:
        simple-escape-sequence
        octal-escape-sequence
        hexadecimal-escape-sequence

    simple-escape-sequence: one of
        /' /" /? //
        /a /b /f /n /r /t /v

    octal-escape-sequence:
        / octal-digit
        / octal-digit octal-digit
        / octal-digit octal-digit octal-digit

    hexadecimal-escape-sequence:
        /x hexadecimal-digit
        hexadecimal-escape-sequence hexadecimal-digit

 

    字符-文字量:
        'c-字符-序列'
        L'c-字符-序列'

    c-字符-序列:
        c-字符
        c-字符-序列 c-字符

    c-字符:
        源字符集中的任何字符,除了
            单引号 ',反斜杠 /,或换行字符
        转义-序列
        统一字符名称

    转义-序列:
        简单-转义-序列
        八进制-转义-序列
        十六进制-转义-序列

    简单-转义-序列: 下列之一
        /' /" /? //
        /a /b /f /n /r /t /v

    八进制-转义-序列:
        / 八进制-数字
        / 八进制-数字 八进制-数字
        / 八进制-数字 八进制-数字 八进制-数字

    十六进制-转义-序列:
        /x 十六进制-数字
        十六进制-转义-序列 十六进制-数字

 

A character literal is one or more characters enclosed in single quotes, as in 'x', optionally preceded by the letter L, as in L'x'. A character literal that does not begin with L is an ordinary character literal, also referred to as a narrow-character literal. An ordinary character literal that contains a single c-char has type char, with value equal to the numerical value of the encoding of the c-char in the execution character set. An ordinary character literal that contains more than one c-char is a multicharacter literal. A multicharacter literal has type int and implementation-defined value.

 

字符文字量是被单引号包围的一个或多个字符,如 'x',也可跟在字母 L 后面,如 L'x'。 前面没有 L 的字符文字量是普通字符文字量,也叫做窄字符文字量。包含单个 c-字符的普通字符文字量具有类型 char, 与执行字符集中该 c-字符的编码数值相等。包含多个 c-字符的普通字符文字量是多字符文字量。多字符文字量的类型是 int,其值由实现定义。

 

A character literal that begins with the letter L, such as L'x', is a wide-character literal. A wide-character literal has type wchar_t.23) The value of a wide-character literal containing a single c-char has value equal to the numerical value of the encoding of the c-char in the execution wide-character set. The value of a wide-character literal containing multiple c-chars is implementation-defined.

 

L 开始的字符文字量是宽字符文字量,如 L'x'。宽字符文字量具有类型 wchar_t23) 包含一个 c-字符的宽字符文字量的值与执行宽字符集中该 c-字符的编码数值相等。包含多个 c-字符的宽字符文字量的值由实现定义。

 

Certain nongraphic characters, the single quote ', the double quote ", the question mark ?, and the backslash /, can be represented according to Table 5.

Table 5 - escape sequences
new-lineNL(LF)/n
horizontal tabHT/t
vertical tabVT/v
backspaceBS/b
carriage returnCR/r
form feedFF/f
alertBEL/a
backslash///
question mark?/?
single quote'/'
double quote"/"
octal numberooo/ooo
hex numberhhh/xhhh

The double quote " and the question mark ?, can be represented as themselves or by the escape sequences /" and /? respectively, but the single quote ' and the backslash / shall be represented by the escape sequences /' and // respectively. If the character following a backslash is not one of those specified, the behavior is undefined. An escape sequence specifies a single character.

 

某些非图形字符,单引号 ',双引号 ",问号 ?,以及反斜线 /,按照表格 5 来说明。

表格 5 - 转义序列
换行NL(LF)/n
水平表格HT/t
垂直表格VT/v
退格BS/b
回车CR/r
换页FF/f
警报BEL/a
反斜线///
问号?/?
单引号'/'
双引号"/"
八进制数值ooo/ooo
十六进制数值hhh/xhhh

双引号 " 和问号 ?,可以单独代表其自身,或分别用转义序列 /"/? 代表,但单引号 ' 和反斜线 / 应该由转义序列 /'// 分别代表。如果跟在反斜线后面的字符没有被指定,其行为是未定义的。一个转义序列代表单个字符。

 

The escape /ooo consists of the backslash followed by one, two, or three octal digits that are taken to specify the value of the desired character. The escape /xhhh consists of the backslash followed by x followed by one or more hexadecimal digits that are taken to specify the value of the desired character. There is no limit to the number of digits in a hexadecimal sequence. A sequence of octal or hexadecimal digits is terminated by the first character that is not an octal digit or a hexadecimal digit, respectively. The value of a character literal is implementation-defined if it falls outside of the implementation-defined range defined for char (for ordinary literals) or wchar_t (for wide literals).

 

由反斜线后面跟着一个,两个或三个八进制数字构成的转义序列 /ooo,用以代表其所指定字符的值。由反斜线后面跟着 x 再跟着一个或多个十六进制数字构成的转义序列 /xhhh,用以代表其所指定字符的值。十六进制序列的数字个数没有限制。八进制或十六进制数字序列分别在遇到第一个不是八进制或十六进制数字的字符时结束。当字符文字量的值超过由实现定义的 char(对于普通文字量)或 wchar_t(对于宽文字量)的数值范围时,其值由实现定义。

 

A universal-character-name is translated to the encoding, in the execution character set, of the character named. If there is no such encoding, the universal-character-name is translated to an implementation-defined encoding. [Note: in translation phase 1, a universal-character-name is introduced whenever an actual extended character is encountered in the source text. Therefore, all extended characters are described in terms of universal-character-names. However, the actual compiler implementation may use its own native character set, so long as the same results are obtained. ]

 

统一字符名称被翻译成其命名的字符在运行字符集中的编码。如果此编码不存在,则统一字符名称被翻译成实现定义的编码。【注:在翻译阶段 1,一旦某扩展字符在源文本中出现,统一字符名称就被引入。因此,所有扩展字符都按照统一字符名称来表示。然而,只要能够产生相同结果,实际编译器实现可以使用其自己的本地字符集。】

 

23) They are intended for character sets where a character does not fit into a single byte.

 

23) 它们由不能用单个字节表达字符的字符集利用。

 

PREV [lex.icon] | NEXT [lex.fcon]上一页 【词法.整型常量】 | 下一页 【词法.浮点常量】
### 如何下载特定版本的 Git 安装程序 如果需要下载指定版本的 Git 安装程序(如 `git-2.13.2-64-bit.exe`),可以按照以下方法操作: #### 方法一:通过淘宝 NPM 的 Git for Windows 索引页 由于官方提供的最新版可能无法满足需求,因此可以通过第三方索引页面获取历史版本。淘宝 NPM 提供了一个完整的 Git 版本列表,可以直接从中找到所需的版本并下载[^3]。 访问地址如下: ``` https://npm.taobao.org/mirrors/git-for-windows/ ``` 进入该页面后,在文件目录中查找目标版本号对应的路径。例如,对于 `git-2.13.2-64-bit.exe`,可以在 `/v2.13.2/` 文件夹下找到对应文件,并点击链接完成下载。 --- #### 方法二:利用国内镜像站点 除了官方渠道外,部分国内开发者维护了 Git 的镜像站点,这些站点通常会同步最新的稳定版本以及一些较旧的历史版本。根据引用中的描述,可以从推荐的国内下载站寻找所需资源[^1]。 需要注意的是,某些镜像站点可能会更新不及时或者停止服务,建议优先尝试上述淘宝 NPM 镜像作为首选方案。 --- #### 方法三:手动编译源码(备用选项) 假如以上两种方式均未能成功定位到具体版本,则还可以考虑从 GitHub 上拉取 Git 源代码自行构建安装包。不过这种方式技术门槛较高,仅适用于熟悉开发环境配置的专业人士。 GitHub 地址如下: ```bash https://github.com/git-for-windows/git/releases ``` 在此处筛选标签(tag),挑选匹配的目标发行版,再依据说明文档执行本地化部署流程即可。 --- ### 示例代码片段 以下是验证已安装 Git 是否为目标版本的小脚本: ```powershell # PowerShell 脚本检测当前 Git 版本 $version = git --version Write-Output "Current Git Version: $version" if ($version -like "*2.13.2*") { Write-Host "Correct version installed!" -ForegroundColor Green } else { Write-Host "Incorrect version, please reinstall." -ForegroundColor Red } ``` ---
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值