1. 规则
1.1 原文
Rule 4.1 Octal and hexadecimal escape sequences shall be terminated
Category Required
Analysis Decidable, Single Translation Unit
Applies to C90, C99
1.2 分类
规则4.1:八进制和十六进制转义序列将被终止
Required必须类规范。
2. 关键描述
八进制或十六进制转义序列应以下列任意一种方式结束:
•另一个转义序列的开始,或
•字符常量的结尾或字符串字面值的结尾。
如果八进制或十六进制转义序列后面跟着其他字符,可能会造成混淆。例如,字符常量’\x1f’由单个字符组成,而字符常量’\x1g’由两个字符’\x1’和’g’组成。将多字符常量表示为整数的方式由实现定义。
如果终止字符常量或字符串字面值中的每个八进制或十六进制转义序列,则可以减少混淆的可能性。
3. 代码实例
例1,规范中例程:
在这个例子中,s1、s2和s3所指向的每个字符串都等价于“Ag”。
const char *s1 = "\x41g"; /* Non-compliant */
const char *s2 = "\x41" "g"; /* Compliant - terminated by end of literal */
const char *s3 = "\x41\x67"; /* Compliant - terminated by another escape */
int c1 = '\141t'; /* Non-compliant */
int c2 = '\141\t'; /* Compliant - terminated by another escape */