Today, I was amused to see the following code in an Orkut community.

#include <stdio.h>

#define decode(s,t,u,m,p,e,d) m ## s ## u ## t
#define begin decode(a,n,i,m,a,t,e)

begin()
{
    printf("Stumped?\n");
}

3 years back, when I was in college, I used to run a mailing list called 'ncoders' which had around 150 members. I deleted it last year after the group became inactive and I lost interest in it. We used to discuss programming and Internet protocols in the group. One day we were discussing how we could obfuscate the main() function in C in a manner that the main() function didn't seem to appear in the code. I wrote the above code and posted it to the group. That's why I was amused to see it again on Orkut today. Probably, the code survived in the inboxes of some subscribers even though the community died. I searched the web to see if this code has been posted in other websites as well and indeed I found many occurrences of this code on the web.

Here's an explanation of the code.

Two tokens can be concatenated together in the preprocessed code using ## preprocessor operator. Now, the meaning of the macro f(s,t,u,m,p,e,d) becomes clear.

So, begin() becomes decode(a,n,i,m,a,t,e)(), decode(a,n,i,m,a,t,e)() becomes m ## a ## i ## n(), and m ## a ## i ## n() becomes main().

No comments

Post a comment

RSS