Monday, October 26, 2009

Without Main Function

Everyone know that can't create c program without main because main is main of
c program and also main will be called first and execute. Then How it's
possible to create c program without main. Here it's the program without main.

#include< stdio.h >
#define selva(b,c,e,s,g,f,d,o) o##g##d##b
#define shark selva(n,y,s,t,a,c,i,m)
void shark()
{
printf("hi");
}


How it works?
Obviously we can't create c program without main function. Then How this program working?!..
In this program i use main function indirectly.
## is named as merging operator. It will merge characters and produce a string.
Here i was created a function 'selva' such that it gets arguments and merge it in some order and returns that string.
And i was called the 'selva' function with arguments 'n','y','s','t','a','c','i','m'. Now track the 'selva' function cleanly. it is merging only 4 characters. By passing these arguments, it'll merge 'm','a','i','n' as 'main'. So now it'll return "main" string. And now shark=main. These operation are done while compiling because we did all these using #define. So it'll run without errors.

0 comments:

Post a Comment