Obfuscating main

By Susam Pal on 31 Jul 2007

Between 2001 and 2005, when I was doing my engineering studies, I used to run a mailing list called ncoders which had around 150 members. We used to discuss programming and network protocols in the mailing list.

One day we were discussing how we could obfuscate the main() function in C such that the main() function didn't seem to appear in the code. I wrote the following code and posted to the mailing list:

#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)

int begin()

This program compiles and runs successfully. It produces the following output:


The mailing list does not exist anymore. The community disappeared gradually and the mailing list was removed. But the code seems to have survived in the inboxes of some subscribers because if we search the web, we can find so many occurrences of this code.

Here is a quick explanation of the code. In C, ## is the preprocessor operator for concatenation.

Thus effectively, begin() is replaced with main().