C / C ++中的十六进制转义码中的位数 [英] number of digits in a hex escape code in C/C++

查看:155
本文介绍了C / C ++中的十六进制转义码中的位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的同事发生争执。她说以下内容:

  char * a =\x000aaxz; 

编译器可以看到\x000aa。我不同意她的意见,因为我认为你可以在 \x 之后最多可以有4个十六进制字符。你可以有超过4个十六进制字符吗?



谁在这里?

解决方案>

§2.13.2/ 4:


逃脱\xhhh由
反斜杠后跟x跟随通过
一个或多个十六进制数字,
用于指定
所需字符的值。
十六进制序列中的数字位数没有限制

八进制或十六进制数字的序列分别由
的第一个字符终止,而不是八进制数字或十六进制
数字。


她是对的。



但是,您可以通过急切的期望来终止它:文字的顺序\x000aaxz指定单个四字符字符串文字。 (2.13.4 / 3)



另请注意,Unicode 使用21位代码点;它不会停止在16位。


I'm having a dispute with a colleague of mine. She says that the following:

char* a = "\x000aaxz";

will/can be seen by the compiler as "\x000aa". I do not agree with her, as I think you can have a maximum number of 4 hex characters after the \x. Can you have more than 4 hex chars?

Who is right here?

解决方案

§2.13.2/4:

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.

She is right.

However, you can terminate it early by eager catenation: the sequence of literals "\x000a" "axz" specifies a single four-character string literal. (2.13.4/3)

Also note that Unicode uses 21-bit code points; it doesn't stop at 16 bits.

这篇关于C / C ++中的十六进制转义码中的位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆