Inferno Web Development
  • Home
  • Forums
  • About
  • Links
  • Contact

Tutorials List

  • C++ Tutorials

Articles

  • Java
  • PHP
  • Photoshop
  • C#
  • C++ Qt GUI
  • C++ Win32 API
  • C++
  • MASM32
  • General News
  • JavaScript
  • Web Development
  • Windows Tweaks

Popular Tutorials

All time:

  • Website Header with 3D Fold Up / Lift Effect
  • C++ Win32 API Tutorial
  • Perfect C++ String Explode Split
  • Simple C++ DLL Loading a Message Box
  • Simple C++ Pointers and References

Related Articles

  • C++ Beginner Programming Video Tutorial
  • C++ Pthreads API
  • Beginner C++ Cout Cin Integer
  • Singleton C++
  • C++ Volatile Keyword

Programming Tutorials

Home

C++ Program Without Main Function

Submitted by Baran Ornarli on Sun, 11/16/2008 - 10:17.
  • C++

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.


5
Average: 5 (2 votes)
»
  • Share Tutorial

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <img> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h4> <h2>
  • Lines and paragraphs break automatically.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • You can use BBCode tags in the text. URLs will automatically be converted to links.
  • Table of contents based on the <h*> tags

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
             oooooo   oooooo     oooo                            ooooooooo.      .oooooo.   
`888. `888. .8' `888 `Y88. d8P' `Y8b
oooooooo `888. .8888. .8' oooo ooo oooo ooo 888 .d88' 888
d'""7d8P `888 .8'`888. .8' `88b..8P' `88. .8' 888ooo88P' 888
.d8P' `888.8' `888.8' Y888' `88..8' 888`88b. 888
.d8P' .P `888' `888' .o8"'88b `888' 888 `88b. `88b ooo
d8888888P `8' `8' o88' 888o `8' o888o o888o `Y8bood8P'


Enter the code depicted in ASCII art style.

Navigation

  • Home
  • Forums
  • Image Gallery
  • Links
  • About
  • Contact

Why Register? Contribute articles and tutorials to ID, earn titles, learn from ID programming projects, and advertise your blog in our forums.

  • Forum Community
  • Register Now
  • Write an Article


Copyright © Inferno Development 2008. All Rights Reserved.