Skip to content


Funky C

It’s pretty funny to know this is valid C99 code, implementing a very basic array assignment and hello world:

%:include <stdio.h>
??=include <stdlib.h>

int main(int argc, char *argv<::>) ??<
    int i??(:> = {1, 2, 3??>;
    printf("Hello world\n");
    return 0;
%>

It’s (ab)using an obscure feature in the C89 and C99 specifications called Trigraph and Digraph, when using GCC you need to pass the ‘-trigraphs’ parameter to enable this functionality. More information can be found on the Wikipedia page about it. I wonder whether people joining code obfuscation games use this.

Posted in Development.

Tagged with , .


7 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Christian Vogel says

    No, it’s not funny at all, if you have to compile legacy code that relies on this and other deformities to be compiled. (especially if it’s things that gcc has deprecated since a long time, and removed…)

  2. Christian Vogel says

    No, it’s not funny at all, if you have to compile legacy code that relies on this and other deformities. (especially if it’s things that gcc has deprecated since a long time, and removed…)

  3. Chris Cunningham says

    They taught us C trigraphs at university during introductory C courses less than ten years ago. (wow, though, I actually learned C before C99 had been adopted as by ANSI.) Using a combination of digraphs and trigraphs in the same file is of course eeeeeevil.

    – Chris

  4. litb says

    tho it’s not funny, you could add
    printf(“%d”, [i]0);

  5. Nicolas says

    Looks like some people might have misread the title, it says ‘Funky C’, not ‘Funny C’. I wouldn’t like to maintain code containing this myself, at all :-)

  6. Jon says

    litb, that’s wrong. I think you meant

    printf(”%d”, 0[i]);

    Although it looks almost right, since ‘i’ is usually used for indices.

  7. Bobby The Programmer says

    The trigraphs were added so that people using keyboards lacking some of the characters needed for C programming could enter them, instead of having characters in their own languages being used as separators.

    As I remember, the Danes said they would not vote for the C++ standard unless trigraphs were included. Ironically, that is Bjarne Stroustrup’s homeland.



Some HTML is OK

or, reply to this post via trackback.