回顾一下,标准中描述了阶段 5-7:
- Each source character set member and escape sequence in character constants and string literals is converted to the corresponding member of the execution character set; if there is no corresponding member, it is converted to an implementation- defined member other than the null (wide) character. 7)
- Adjacent string literal tokens are concatenated.
- White-space characters separating tokens are no longer significant. Each preprocessing token is converted into a token. The resulting tokens are syntactically and semantically analyzed and translated as a translation unit.
现在我同意空白字符在第 7 阶段不再重要,但难道不能在第 4 阶段之后就摆脱它们吗?有没有一个例子表明这会有所作为?
当然应该意识到,删除分隔标记的空白字符在这个阶段不起作用,因为第 4 阶段之后的数据由预处理标记组成。这个想法是为了在早期阶段摆脱分隔预处理标记的空格。
最佳答案
考虑这个源代码
char* str = "some text" " with spaces";
在第 5 阶段,它被转换为这些标记(每行一个标记):
char
*
str
=
"some text"
" with spaces"
此处重要的是“some text”和“with spaces”中的空格。
之后所有标记之间的空格(见上文)都将被忽略。
如果您在第 5 步之前删除空格,您会得到其他字符串文字,例如“sometext”
关于c - 在 C 语言的翻译阶段 5 和 6 中,空格什么时候有意义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31874715/