ANSI/ISO 9899-1990(ansi c90,又称c89)标准将C语言环境(environment)分为两个:1、翻译环境(translation environment)和2、运行环境(execution environment)。在介绍translation environment 中的翻译阶段(translation phases)的第一步时,提到”Trigraph sequences are replaced by corresponding single-character internal representation”,翻译过来就是“三字符序列是由相应的单字符的内部表示形式取代”。
具体的trigraph sequences 有哪些,而它们会被替换成哪些字符如下表所示:trigraph sequence | replacement | trigraph sequence | replacement |
---|---|---|---|
??= | # | ??( | [ |
??/ | \ | ??) | ] |
??’ | ^ | ??< | { |
??! | | | ??> | } |
??- | ~ |
一个测试程序如下:
#includeint main(){ printf("what??!\n"); return 0;}
在试图用程序模拟时,产生如下警告(环境为codelite 10.0.4+gcc 6.3.0):
warning: trigraph ??! ignored, use -trigraphs to enable [-Wtrigraphs] printf("what??!\n");
说明在编译时要开启-trigraphs选项
最后结果和预计的一样为what|
. 一个容易犯错的例子:printf("Delete file (are you really sure??):");
;这里我们期望的是打印出 Delete file (are you really sure??):
,最后打印的是Delete file (are you really sure]:
,与想象的不一样。