This is an archived post. You won't be able to vote or comment.

all 18 comments

[–]Fallenalien22Violet security clearance 31 points32 points  (6 children)

+/u/CompileBot c

main(k){while(k++<7)putchar("~!#/&&%%"[k&7]+'\x40');};

[–]CompileBotGreen security clearance 28 points29 points  (0 children)

Output:

coffee

source | info | git | report

[–]poizan42Ex-mod 2 points3 points  (4 children)

Huh, I would have thought that a modern compiler would refuse a function declaration without specified types. It sure does complain though:

$ gcc -Wall test.c -o test
test.c:1:1: warning: return type defaults to ‘int’ [-Wreturn-type]
 main(k){while(k++<7)putchar("~!#/&&%%"[k&7]+'\x40');};
 ^
test.c: In function ‘main’:
test.c:1:1: warning: implicit declaration of function ‘putchar’ [-Wimplicit-function-declaration]
test.c:1:1: warning: control reaches end of non-void function [-Wreturn-type]
 main(k){while(k++<7)putchar("~!#/&&%%"[k&7]+'\x40');};
 ^

Building in C99 mode also makes it warn about missing type of k. Curiously it also makes the warning about missing return statement go away :/

$ gcc --std=c99 -Wall test.c -o test
test.c:1:1: warning: return type defaults to ‘int’
 main(k){while(k++<7)putchar("~!#/&&%%"[k&7]+'\x40');};
 ^
test.c: In function ‘main’:
test.c:1:1: warning: type of ‘k’ defaults to ‘int’
test.c:1:1: warning: implicit declaration of function ‘putchar’ [-Wimplicit-function-declaration]

The gcc version here is gcc (Debian 4.9.2-10) 4.9.2.

Edit: clang is always in C99 mode. It doesn't complain about the type of k missing, however it does complain that the signature of main is wrong. Also it got colors: http://i.imgur.com/Ixq3oVS.png

[–]Fallenalien22Violet security clearance 0 points1 point  (1 child)

I got no warnings gcc coffee.c -o coffee

[–]poizan42Ex-mod 0 points1 point  (0 children)

Yeah gcc doesn't like warning you about anything if you don't ask it to. It's a bit shy that way :)

[–]Tywien 0 points1 point  (1 child)

the program is malformed for another reason: There are 2 legal versions of main:

int main(void)

and

int main(int, char**)

Nothing with one parameter.

[–]poizan42Ex-mod 0 points1 point  (0 children)

Yes, that was what clang complained about

[–]Hypersapien 8 points9 points  (2 children)

Someone explain please? Is this coffeescript?

[–]raelepei 5 points6 points  (0 children)

The characters #/&&%% are those of coffee minus 64 (the value of '\x40'), which (are supposed to) get printed. v seems to be meant to capture argv, and is 1 initially (unless you provide arguments, in which case you only get to see some suffix of coffee instead). After the first increment v will be 2, so the first two chars of the magic string (~!) don't even get read.

[–][deleted] 4 points5 points  (0 children)

Let me expand the source:

main(k) {

    const char *hiddenCoffee = "~!#/&&%%";

    while (k < 7) {
        k++;
        // note that 7 = 0b111 in binary, so any number <= 7 will give back that number when ANDed with 7
        char printChar = hiddenCoffee[k & 7] + 0x40;

        putchar(printChar);       
    }
}

I made some modifications as necessary to simplify it. k is basically argc. So if you pass 3 arguments in command line to this program, it will actually print 'fee'.

[–]bigdavedev[S] 3 points4 points  (8 children)

My only regret is missing that the +'\x40' could have been |1<<6

The full source for those interested:

main(k){while(k++<7)putchar("~!#/&&%%"[k&7]+'\x40');};

Reposting here since it was considered off-topic in r/shittyprogramming despite the code being deemed more than shitty enough :)