[AD] Proposal for new magic main

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


After some Ping-Pong with Jeremiah Blanchard, the Darwin/MacOS X patch is
almost ready to be merged (I'll post it soon). However, as I already said in
a previous thread, the current magic main emulation (based on END_OF_MAIN)
breaks under Darwin.

So I'm proposing this new magic main emulation (also suggested by Sven) for
4.1.x:

AL_FUNC(int, _main, (void *_mangled_main, int argc, char *argv[]));

#if (!defined ALLEGRO_NO_MAGIC_MAIN) && (!defined ALLEGRO_SRC)

   extern int _mangled_main(int argc, char *argv[]);

   #define main                                               \
                                                              \
      main(int argc, char *argv[])                            \
      {                                                       \
         return _main((void *)_mangled_main, argc, argv);     \
      }                                                       \
                                                              \
      int _mangled_main

#endif

with of course a little tweak (WinMain instead of main) under Windows.
The big advantage is that END_OF_MAIN() is no longer needed, the drawback is
that it is replaced by the mandatory ISO C-compliant declaration of main(),
i.e 'int main(int argc, char *argv[])'.

The patch is located at:
http://www.multimania.com/ebotcazou/dev/magic_main2.zip

It has been successfully tested with gcc (Linux, Darwin, Mingw32, QNX) and
Borland C++, only MSVC remains on the todo list.

--
Eric Botcazou
ebotcazou@xxxxxxxxxx



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