xorl %eax, %eax

C Trigraphs

with 4 comments

Most people that have read ISO 9899:1999 (aka. C99) will know this but for those of you who haven’t read it yet.. Read it! Well, trigraphs is a funny Standard feature of the C language’s pre-processor. They are sequences of three letter words that are being replaced by the C pre-processor. The complete list is:

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

And can be found at paragraph 5.2.1.1 of the IEC/ISO 9899:1999 standard. And here is some fun things that you can do with these:

sh-3.2$ cat tri.c<
??=include <stdio.h> 
int main(void)??<printf("??(Hello World??)??/n??'_??'??/n");return 0;??>
sh-3.2$ gcc tri.c -trigraphs -o tri -std=c99 -pedantic
sh-3.2$ ./tri

[Hello World]
^_^
sh-3.2$

Yeah… useless.. But still fun!

Written by xorl

January 1, 2009 at 09:20

Posted in C programming

4 Responses

Subscribe to comments with RSS.

  1. Typo?
    ??< = {

    dxp

    June 28, 2009 at 19:35

  2. Yes, indeed. Thanks, I fixed it.

    xorl

    June 28, 2009 at 22:39

  3. This blog very funny !! :-b

    clne

    August 18, 2010 at 16:36

  4. The ASCII special characters [, ], {, }, |, and \ occupy character set positions designated as alphabetic by ISO. In most European national ISO-646 character sets, these positions are occupied by letters not found in the English alphabet.

    So there you have it. They’re not *entirely* useless. :-)

    mfukar

    November 18, 2010 at 14:27


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s