1. trigraph三字符组
据说是为了照顾旧式键盘,还是为了键盘坏了,或者是使用非ASCII字符编码的语言输入方便,设计了一些三元字符组,两个问号加一个符号在预处理时替换为一个字符。MSDN这么解释
The source character set of C source programs is contained within the 7-bit ASCII character set but is a superset of the ISO 646-1983 Invariant Code Set. Trigraph sequences allow C programs to be written using only the ISO (International Standards Organization) Invariant Code Set.
这些三字符组有
Trigraph replacement | Trigraph replacement | Trigraph replacement |
??&#61; # | ??( [ | ??< { |
??/ / | ??) ] | ??> } |
??’ ^ | ??! | | ??- ~ |
2. alternative tokens
下面几对符号等价
Alternative Primary | Alternative Primary | alternative Primary |
<% { | and && | and_eq &&#61; |
%> } | bitor | | or_eq |&#61; |
<: [ | or || | xor_eq ^&#61; |
:> ] | xor ^ | not ! |
%: # | compl ~ | not_eq !&#61; |
%:%: ## | bitand & | |
于是下面的程序就是合法的C&#43;&#43;程序&#xff0c;而且很标准&#xff1a;
??&#61;include
int suM(int a, int b)
<%
int arr<:2:>;
arr<:0:> &#61; a,
arr<:1 ??/
:> &#61; b;
return arr??(0:> &#43; arr??(1];
%>
int main(int argc, char* argv[])
??<
bool bv &#61; false;
std::cout<<"Program name:"< if( ( bv ??! 1 and 1) not_eq false){
int iv &#61; 1333;
std::cout<}
std::cout<<"3&#43;4&#61;"< return 0;
??>
用GCC编译的时候加上-trigraphs 选项即可&#xff0c;VC默认编译不通过&#xff0c;可能需要编译选项&#xff0c;暂时还没找到