Skip to main content
GameDev.net gamedev.net
🔒 Locked

Your indirect history lesson for the day

Started by Sneftel Mar 26, 2011 at 9:07 PM 5 replies 1k views
Original Post
Sneftel
Sneftel

#include <cstdio>
using namespace std;

#define SECRET(x) 0[#x]

int main()
{
printf("%c\n", SECRET([));
printf("%c\n", SECRET(??());
printf("%c\n", SECRET(<<img src='http://public.gamedev.net/public/style_emoticons/<#EMO_DIR#>/smile.gif' class='bbc_emoticon' alt=':)' />);
}


Discuss.
ApochPiQ
ApochPiQ
So... you're abusing trigraphs, stringification operators in macros, and the array-index/index-array isomorphism in C/C++ syntax.

Aside from the obvious tools of evil, what are we supposed to glean from this?
Antheus
Antheus
[][

If I'm reading the commutativity and trigraphs right.
Sneftel
Sneftel
Hey, trigraphs have bitten more than one programmer who commented

// Why isn't this printing???????????/
printf("hello, world!\n");
BTW, the output of the last line should surprise you.
Sneftel
Sneftel
Because whatever.

Actually, the whole thing can be put more succinctly:



#include <cstdio>
using namespace std;

int main()
{
char secret <:??) = "<:??)";
printf("%s\n", secret);
}


(Incidentally, that formulation illustrates a distinct incompatibility of Visual C++, whereas the original one just happens to compile. To compile this one, disable language extensions in the project properties window.)
owl
owl
Trigraphs seem to be disabled by default on MinGW. "warning: trigraph ??( ignored, use -trigraphs to enable". And if you enable them it will warn about convertions.
[size="2"]I like the Walrus best.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.