C++ Program Without Main Function
Ever wanted to name your C++ main() function differently? We use a little C++ trick to rename our main() function to InfernoDevelopment().
The following code will actually replace InfernoDevelopment with main before compiling the final exe file.
#define tutorial(i,n,f,e,r,N,o) e##f##r##N
#define InfernoDevelopment tutorial(f,l,a,m,i,n,g)
int InfernoDevelopment(){
printf("Hello, welcome to Inferno Development, join us at our forums!\n");
return 0;
}
We first define a C++ definition macro called "tutorial", which has a number of parameters.
The operator ## concatenates two arguments leaving no blank spaces.
combine(c,out) << "merge it";
So when combine is called, the arguments a and b are interpreted as text and concatenated. This is what happens when you call "combine(c,out)":
cout << "merge it";
That's how we're using InfernoDevelopment(). It simply combines it's arguments in a specific order. So InfernoDevelopment() gets replaced with main().
When you code is compiled the preprocessor replaces InfernoDevelopment with tutorial(f,l,a,m,i,n,g), which is actually replaced first by main (because 'efrn' arguments in 'inferno' correspond to 'main' in 'flaming'). This is just a trick to replace all that with main.
Remember though we haven't really changed any code (the preprocesser simply replaces all definitions), this code and a simple main() program will look exactly the same.
If you are confused or need help, visit our forums.

Anonymous (not verified)
I honestly can't see any
I honestly can't see any advantage to this whatsoever. It's bad enough that microsoft introduce WinMain() (where I can actually see some order to their madness), renaming main() just causes confusion to other developers that might be working on the code.
If someone came to me with this and asked me, 'where's the entrypoint of this app?', in a large app it could take days to manually sift through the code and figure out where the hell main() is just to find that it's been arbitrarily named to something else for no good reason.
This kind of code just wastes time which could be used doing something that's *actually constructive*
Baran Ornarli
It's just a cool little
It's just a cool little trick, it doesn't mean anyone will use this in a real project.
krishanu chatterjee (not verified)
it gr8....i was just
it gr8....i was just challenged.hope he dosent know dis
bhushan (not verified)
Hey. The trick might be good;
Hey. The trick might be good; however it lacks in explanation. I did not understand easily the macros and how it InfernoDevelopment is replaced with main at runtime, the first time I read it. So if I am not wrong, as you mentioned, the macro returns efrn and you find "fern" in InfernoDevelopment. And return type of InfernoDevelopment is return type of tutorial, which is again efrn. But this time you are calling Tutorial with a, m, i, n for e, f, r, n parameters in Tutorial. But how did f,l...g vouch for i,n....o parameters? Also, the returned value is efrn for Tutorial. And InfernoDevelopment is getting its return value by a returning value from Tutorial, which is efrn as well. So, when does it actually interpreted as main. This explanation in clear text is lacking. Although, I am not expert at writing #define macros, I say that I understand them quite okay. But I may be wrong and you could correct me providing some explanation....
Thanks for reading,
Bhushan
Anonymous (not verified)
wouldn't it just be easier to
wouldn't it just be easier to use '#define InfernoDevelopment main'? or is there something in the compiler that requires a work around?
unless the intention is to confound, hiding the functionality in a couple of words that sound like they match the "feel" of the project, so are easily overlooked. If that is the case, then good on ya.
also brushan, the first #define tutorial(...) e##f##r##N takes any subsequent tutorial(...) containing the same number of arguments and returns the values of said arguments found in the possition of e f r and N and concatinates them in the specific order.
therefor when tutorial is used later the argument i = f, argument n = l, etc. (noting that n != N) and the define for InferniDevelopment replaces it with the values of the tutorial arguments concatenated as defined prior. (which spells main)
hope that makes more sense to you.
Post new comment