Programming Tutorials
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.
#include <stdio.h> #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. Then using the ## operator which just merges each letter we have a result of tutorial macro. The code basically returns efrN, whatever the parameters are.
So then we define InfernoDevelopment as the result of our previous C++ definition macro. a->f m->e i->r n->N and if we reorder the f and i, then that spells main.
Remember though we haven't really changed any code, this code and a simple main() program will look exactly the same.
If you need help, ask in our forums.


Post new comment