Re: Fwd: Re: [AD] New END_OF_MAIN() Proposal

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Tuesday 30 November 2004 18:11, Dustin Dettmer wrote:
> Forcing two arguments in the main function isn't all
> that bad IMO, SDL does it, right?

Yes, but we can't because that could break existing code.

> Actually, how does SDL do it, do they have an
> END_OF_MAIN() aswell?

No. There are two distinct issues: to rename the user's main() to something 
different and to call it from our own main.
Renaming it is easy, just #define main _mangled_main (as Allegro does) or 
#define main sdl_main (as SDL does). Allegro then calls _mangled_main 
through a pointer from its own main routine (which is why it works with 
both main(void) and main(int,char**)). SDL just calls sdl_main (so it 
requires main(int, char**)), but that's really only a minor difference.
The real difference is how to handle the real main function. SDL just 
defines its own in the library - so you can't disable it's main mangling 
(someone correct me if I'm wrong - I looked and couldn't find how to do 
it).
On MacOS X and Windows, END_OF_MAIN() is a macro that expands to Allegro's 
own main() (or WinMain()) routine. In DOS, it always expands to nothing, 
in UNIX it expands to a pointer that is initialized to point at the 
_mangled_main which is called from the true main() in the Allegro library 
(a weak symbol, apparently), if magic main support has been enabled - 
otherwise it evaluates to nothing, as in DOS.

In both MacOSX and Windows, the problem is that there's no way to hook the 
main function without declaring our own multiple times and at the same 
time allow for the user to disable that behavior (through 
ALLEGRO_NO_MAGIC_MAIN).

Evert





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/