关于ANSI:为什么C++中有替代令牌?

Why are there alternative tokens in C++?

本问题已经有最佳答案,请猛点这里访问。

Possible Duplicate:
Why are there digraphs in C and C++?
What does the C ??!??! operator do?!

在C++中,对于[]和{},还有其他的代币。

例如,以下代码编译:

1
2
3
4
%:include <stdio.h>
int main() <%
    printf("Hello World!");
}

我考虑了一会儿,但没想到有什么适用性,这有什么逻辑上的原因吗?


他们是C的宿醉,真的。有些C的实现中并不是所有字符都可用(例如一些没有方括号的EBCDIC变体)。

C99基本原理文件第5.2.1.1 Trigraph sequences节规定:

Trigraph sequences were introduced in C89 as alternate spellings of some characters to allow the implementation of C in character sets which do not provide a sufficient number of non-alphabetic graphics.

The characters in the ASCII repertoire used by C and absent from the ISO/IEC 646 invariant repertoire are #, [, ], {, }, \, |, ~, and ^