app without main()

Hi all,
How can programs entry point be changed?
For example, windows api uses WinMain as an entry point instead of main and sdl uses sdl_main.
Is there somewhere a main() hidden in .lib files that calls WinMain?
Or is these a compiler setting for that?
I think in VC++ there is a setting for it...I don't know where it is though.
main() is called by the C or C++ runtime. The main() for windows lives in a library, same for SDL apps. The entry point can be changed, but it requires deep magic that is compiler/library/linker specific.

http://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_24.html

http://www.yosefk.com/blog/the-c-sucks-series-the-quest-for-the-entry-point.html
thank you very much
What!?

Don't do that!

There are very few legitimate reasons to change a program's entry point from main() (or, on Windows, WinMain() ).

SDL doesn't change the entry point, it uses a trick to play with the percieved entry point. (I don't think SDL's reason is legitimate anyway.)

If there is special library initialization that MUST be done, put it in a class instanciation in a library file, or a DLL loading entry point, or simply require the user to call library initialization. Exactly how hard is this?

1
2
3
4
5
6
7
8
#include <iostream>
...
#include <foo.hpp>

int main( int argc, char** argv )
  {
  FooInit( argc, argv );
  ...

Why not use the Language Standard entry point?


If you are only asking about why there is main() vs WinMain() vs DllMain() vs etc, then you are getting into the realm of compiler/OS extensions. A compiler can expect your main function to be called anything it wants; only the language requires it to be "main". Windows OS designers decided that there needs to be a change when initializing GUI code (which is significantly different than terminal program startup). You can still write GUI programs with main(), but things are what they are...

Please don't add to the mess and make things difficult. Life is so much easier if you just do things the Right Way.

Hope this helps.
Douas wrote:
Don't do that!


Oh, come on. Everyone should write their own entry code at least once in their life.

It's too painful to be habit forming.
LOL, I hadn't thought of it that way!

You are right, of course. :-)



You could write all the code in the constructor of a static object and leave main() empty.
Don't do that!

I wasn't going to...
I just wanted to know, how is that done.
Topic archived. No new replies allowed.