bianbian coding life

便便代码人生: 关注技术, 翻译文档, 偶尔动动手

[晕] 居然还有这种东西:C++ Trigraph

Posted by bianbian on 2007-08-01 15:34

本文Tags:

听说为了照顾某些键盘坏了又换不起的,可以使用这种3字符的串来代替一些特殊字符,preprocess的时候会替换掉:

#: ??=
\: ??/
^: ??’
[: ??(
]: ??)
{: ??<
}: ??>
|: ??!
~: ??-

于是程序就这样了:

  1. //: S03:trigraph.cpp
  2. ??=include <iostream>
  3.  
  4. int main(int argc, char* argv??(??)) ??<
  5.     using namespace std;
  6.     unsigned int n;
  7.     if (argc != 2 ??!??! (n = atoi(argv??(1??))) <= 0)
  8.         return 1;
  9.     cout << ??-(n ??' 0xf0f0) << '??/n';
  10.     return 0;
  11. ??>

我就奇怪了,键盘换不起,眼睛换换就那么便宜吗?

标签:

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

2 Responses to “[晕] 居然还有这种东西:C++ Trigraph”

  1. WG Says:

    故意用来混淆代码的吧……

  2. wangcong Says:

    NO!
    显然不是为键盘坏了准备的,你怎么知道别人坏的是哪个键呢?
    引入trigraph的原因是字符编码问题。iso646规定说各国可以用自己国家的一些符号替换掉ASCII里的”{”"}”"[”"]”等,这样问题就来了。那些字符明明不是ASCII,但仍然可以用到程序中,甚至可能没错,但程序读起来明显就费劲了。为了照顾这种情况,C/C++语言标准才考虑用trigraph来把它们给替换掉。

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

(required)