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.
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…)
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…)
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
tho it’s not funny, you could add
printf(“%d”, [i]0);
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
litb, that’s wrong. I think you meant
printf(”%d”, 0[i]);
Although it looks almost right, since ‘i’ is usually used for indices.
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.