Skip to content

Comment on Write a program that makes 2 + 2 = 5

Comments

Here's mine :

    $ cat test.c
    #include <stdio.h>
    
    int main() {
        int a = 3;
        int b = 3;
    
        // aren't we supposed to add 2 and 2 ??/
        a = 2;
        b = 2;
    
        printf("%d\n", a + b);
    
        return 0;
    }
    $ gcc -W -Wall -trigraphs test2.c 2>/dev/null
    $ ./a.out
    5
    $

Is the trick here the "-trigraphs" flag, or the fact that you are showing us test.c but compiling test2.c? Both approaches seem like they should work.

It's the trigraph ??/ which translates to a \.

The trigraph appears in the file "test.c". If you look at the compilation command, you will see that that is not the file that is actually compiled.

If you compile "test.c" you will see that that isn't relevant issue.

Very sneaky. For anyone else wondering why this works, look up trigraphs.

And after looking it up, you better then realise that if you actually ever use them in production code you better have a really good reason, or your colleagues will forever curse your name..

I think the above is probably the first time I've seen trigraphs used in the last 20 years or so.

http://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C

sorry for spoiling:

"??/" got replaced by "\"

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.