这在 clang 和 gcc 中编译时没有警告:
const char *foo = "\%";
生成的字符串与 "%"
相同。
这个转义是为了什么?在哪里可以找到完整的转义列表?
我想可能是为了转义二合字母,但其他二合字母字符会产生警告(例如 "\:"
)。
感谢您的帮助!
最佳答案
回答我自己的问题:它支持 SCCS,这是一个有 40 年历史的版本控制系统,甚至早于 RCS。哈!
深入研究编译器,clang 支持这个 because it thinks gcc does :
case '(': case '{': case '[': case '%':
// GCC accepts these as extensions. We warn about them as such though.
谎言!出现警告,但仅带有 -pedantic
标志(在两个编译器中)。
哦,还有 gcc?它supports the first three for emacs ,我想这很容易混淆:
/* `\(', etc, are used at beginning of line to avoid confusing Emacs. */
case '(':
case '{':
case '[':
但最后一个:
/* `\%' is used to prevent SCCS from getting confused. */
case '%':
if (pedantic)
pedwarn ("non-ANSI escape sequence `\\%c'", c);
return c;
SCCS 支持!这是光荣的!
关于c - C 中的反斜杠百分比转义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34142682/