Re: [AD] END_OF_MAIN removal patch for msvc

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


On 19 Nov 2008, at 09:17, Elias Pschernig wrote:
I didn't read the whole thread, but I'm all for this solution. The less
magic is going on behind the users back, the better. And if we simply
require users to not have any kind of "main" of their own, things never
can be inadvertently made non-cross-platform.

I'm not completely sure, but I think SDL does it that way for a long
time - they put the different main/Winmain functions into a separate
library, something like sdlmain.so. That way all normal users simply
will link to sdlmain.so which provides the real main() function. Someone
doing things like writing a language binding would provide their own
main() implementation. Really sounds like the ideal thing to do, and
finally my programs no longer will fail to compile under windows and OSX
because I forgot END_OF_MAIN :)

I was going to make a longer post responding to a number of things I saw going by, but I'll be brief now and defer the longer post to a later point (which may be in the infinite future). I do want to make one thing clear though: we do not aim for a solution where the user gets an easy choice of two alternatives, one of which works everywhere (but may be more hassle than needed on some platforms) and one that doesn't. As stated before, the user does need to have the option to choose to ignore platform independence, but they have to do extra work to do that. Linux, Windows and Mac OS X are all equal as far as Allegro is concerned and we present the user with one way of doing things that works the same on all platforms.

So I'll second (third?) Peter Hull's proposal. It's not quite my ideal solution, but it's probably as close as we can get. From what I remember, SDL does indeed do something like this, although it also does the equivalent of #define main _mangled_main.

The rest of this mail is me thinking as I type and not necessarily coherent.

We can add that type of syntactic sugar if we really wanted to, put Allegro's main in a separate library on platforms where it may be needed (OS X, UNIX if we really do need argv) and do nothing at all for other platforms (Windows, UNIX if we really don't need argv).

In that case, we'd have:
- users write a main function of their choice (int main(void) or int main(int, char **)), #include "allegro.h"/"allegro/allegro5.h" and link to whatever libraries they need (liballeg, liballegmain, liballegrandomaddon, etc); tools like allegro-config (or pkg-config once we have it) hide the gory details.
 - allegro.h #defines main alegro_main_wrapper or something similar.
- allegmain contains main() and extern allegro_main_wrapper(int, char**). I think that should properly work for both versions of main () (something like that did on UNIX anyway).

Users who want to do their own main() function:
- #define ALLEGRO_NO_MAGIC_MAIN (say ;)) before #include <allegro.h>, in which case main isn't re#defined.
 - don't link to liballegmain
 - are on their own.

I'm not sure where this differs from the current END_OF_MAIN() macro except in somehow not needing it... maybe one of the steps putting main() in an external library doesn't work?

OS X related question though: will this really make it easier to combine things like Scheme and Allegro? Wouldn't the same issue pop up as with the current scheme?

Evert




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