Re: [AD] No need for END_OF_MAIN (Windows)

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


[In the unlikely chance this mail gets through..]
On Fri, 2005-05-13 at 15:35 +0200, Evert Glebbeek wrote:
> > This patch removes the need to place END_OF_MAIN() macro at the end of
> > main function by extending "#define main" macro to have all needed
> > code.
> 
> Unfortunately, this will break code that has a struct member named main.
> That may sound like an academic case, but it probably isn't.

I agree. Allegro 3.12 as well as Allegro 4.0 programs might use main as
a struct memember, and then with the new version, suddenly would stop
working (but I agree, it's an academic case).

> It also suffers from the problem that int _mangled_main(); doesn't mean the
> same thing in C++ as it does in C, although you can probably get around
> that by replacing () with (int argc, char **argv).

Hm, wouldn't have though of that, but yes, the empty parenthesis are C
only, in C++ they would declare a function with no parameters, even
inside extern "C".

> How do others feel about this for the 4.3 branch?

I think we should try to find a way with not so much magic. Currently,
two platforms need it, for different reasons:

Windows: Instead of main(), the main function is called WinMain, so all
the magic involved is to provide a WinMain which calls the user main.

OSX: The user's main function must run in a thread created by Allegro,
so we provide another main, which creates that thread and calls the user
main.

Both could be solved by simply providing main/WinMain inside Allegro,
and have the user code use e.g. allegro_main as main function. Something
like:

void allegro_main(void)
{
    /* program goes here */
}

Another problem is when the ALLEGRO_NO_MAGIC_MAIN behavior is desired..
but I'm not too sure how this currently works e.g. in OSX. I guess, just
loading Allegro at runtime in OSX isn't as easy as in windows or linux,
since some pre-allegro_init setup code seems to be in the
allegro-provided main() function.

[Oh, btw, speaking of OSX, Angelo told me in #allegro he sold his Mac,
so he won't do any OSX work in the next time, so OSX all rests on Peter
Hull and Thomas Harte and whoever does testing on it for now.]

> > BTW I also tried to remove END_OF_MAIN macro for other platforms and
> > find out that it sets _mangled_main_address by couldn't find where it
> > is used.

E.g. in OSX, the real main() function is in src/macosx/main.m, which
starts a thread with the function pointed to by _mangled_main_address
(the user's main).

> What version of Allegro did you use to make your patch? END_OF_MAIN() is
> already optional in DOS and *NIX (although the *NIX port can be configured
> to make it nescessary), but needed in Windows and MacOS X. Getting rid of
> it on as many platforms as possible is nice, but unless we can do the same
> for MacOS X (which, if I recall correctly, we can't) there's not much point
> in trying too hard.

Exactly, that's the main reason why there's no point with a patch like
this. As long as END_OF_MAIN is needed in OSX, all standard uses of
Allegro on all platforms need it, else we lose source portability.

-- 
Elias Pschernig





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