c/c++ trigraph

原创 2007年10月06日 19:55:00
一下内容摘自msdn:
Trigraphs

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. Trigraphs are sequences of three characters (introduced by two consecutive question marks) that the compiler replaces with their corresponding punctuation characters. You can use trigraphs in C source files with a character set that does not contain convenient graphic representations for some punctuation characters.

Table 1.1 shows the nine trigraph sequences. All occurrences in a source file of the punctuation characters in the first column are replaced with the corresponding character in the second column.

Table 1.1   Trigraph Sequences

Trigraph Punctuation Character
??= #
??( [
??/ /
??) ]
??’ ^
??< {
??! |
??> }
??- ~

A trigraph is always treated as a single source character. The translation of trigraphs takes place in the first translation phase, before the recognition of escape characters in string literals and character constants. Only the nine trigraphs shown in Table 1.1 are recognized. All other character sequences are left untranslated.

The character escape sequence, /?, prevents the misinterpretation of trigraph-like character sequences. (For information about escape sequences, see Escape Sequences.) For example, if you attempt to print the string What??! with this printf statement

printf( "What??!/n" );

the string printed is What| because ??! is a trigraph sequence that is replaced with the | character. Write the statement as follows to correctly print the string:

printf( "What?/?!/n" );

In this printf statement, a backslash escape character in front of the second question mark prevents the misinterpretation of ??! as a trigraph.

 

相关文章推荐

关于C/C++中的trigraph

转载自http://blog.sina.com.cn/s/blog_4b687eac01008ice.html,作者:小胖妞妞 今天看书看到这个词,书上没给解释,上网查了下,意思很"隐讳",...

C/C++内存泄漏及检测

原文链接:点击打开链接 “该死系统存在内存泄漏问题”,项目中由于各方面因素,总是有人抱怨存在内存泄漏,系统长时间运行之后,可用内存越来越少,甚至导致了某些服务失败。内存泄漏是最难发现...

【C/C++多线程编程之六】pthread互斥量

多线程编程之线程同步互斥量       Pthread是 POSIX threads 的简称,是POSIX的线程标准。           Pthread线程同步指多个线程协调地,有序地同步使...

C/C++_atoi,itoa功能及其实现原理

itoa将数字转换成指定进制的字符串 itoa是广泛应用的非标准C语言扩展函数。由于它不是标准C语言函数,所以不能在所有的编译器中使用。但是,大多数的编译器(如Windows上的)通...

关于C/C++中的内存泄漏——程序员面试高频题

前几天面试多益网络的时候,面试官就问到了C/C++中的内存泄露问题。这也是很多公司面试时候的高频题,好吧,那就来学习下吧~ 到底什么是内存泄漏?是什么导致了内存泄漏?如何避免?又如何检测呢? ...

用命令行编译C/C++程序

操作步骤如下: 1.在命令行下,先运行vcvars32.bat(此文件在VC安装目录\Bin文件夹里,其中设置了环境变量和路径等信息)。或者,手动修改环境变量:   path=你安装VS的路径\V...

C/C++中参数的传递机制

一、函数参数传递机制的基本理论   函数参数传递机制问题在本质上是调用函数(过程)和被调用函数(过程)在调用发生时进行通信的方法问题。基本的参数传递机制有两种:值传递和引用传递。以下讨论称调用其他函...

实战c++中的string系列--函数返回局部变量string(引用局部string,局部string的.c_str()函数)

当函数返回字符串的时候,我们可以定义返回string和string&。1写一个返回string引用的函数std::string & TestStringReference() { std::s...

C/C++通过WMI和系统API函数获取获取系统硬件(cpu,内存,显卡,网卡)配置信息

前段时间由于项目需要,要求做一个服务器的实时性能监控(CPU、内存、网络利用率等)和读取服务器的硬件配置参数的接口供项目组使用,就是一个类似于鲁大师之类的东东吧...      当然第一想法肯定是利...

c/c++ 开发中常见的坑

总结一下自己遇到的坑,吸取教训,避免第二次、第三次在同一个地方扑街。 语言类 变量初始化问题 众所周知,局部变量在函数调用开始时创建,函数调用完成返回时“销毁”。值得注意的是,这里根本没有所谓...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:c/c++ trigraph
举报原因:
原因补充:

(最多只允许输入30个字)