[SDL] sdlmain

Roman Kyrylych roman.kyrylych at gmail.com
Wed Jul 5 00:40:06 PDT 2006


> I suggest to see how this is done in Allegro:
>      int main(void)
>      {
>         allegro_init();
>         /* more stuff goes here */
>         ...
>         return 0;
>      }
>      END_OF_MAIN()
>
> END_OF_MAIN is a special macro which is different for different
> platforms. See Allegro's headers for more info.

Did all missed this message?
OK, I explain more.

alconfig.h:
#ifndef END_OF_MAIN
   #define END_OF_MAIN()
#endif

alunix.h
#ifdef ALLEGRO_WITH_MAGIC_MAIN

   #ifndef ALLEGRO_NO_MAGIC_MAIN
      #define ALLEGRO_MAGIC_MAIN
      #define main _mangled_main
      #undef END_OF_MAIN
      #define END_OF_MAIN() void *_mangled_main_address = (void*) _mangled_main;
   #else
      #undef END_OF_MAIN
      #define END_OF_MAIN() void *_mangled_main_address;
   #endif

#endif

alwin.h:
#if (!defined ALLEGRO_NO_MAGIC_MAIN) && (!defined ALLEGRO_SRC)

   #define ALLEGRO_MAGIC_MAIN
   #define main _mangled_main
   #undef END_OF_MAIN

   /* disable strict pointer typing because of the vague prototype below */
   #define NO_STRICT

   #ifdef __cplusplus
      extern "C" int __stdcall WinMain(void *hInst, void *hPrev, char
*Cmd, int nShow);
   #endif

   #define END_OF_MAIN()                                                     \
                                                                             \
      int __stdcall WinMain(void *hInst, void *hPrev, char *Cmd, int nShow)  \
      {                                                                      \
         return _WinMain((void *)_mangled_main, hInst, hPrev, Cmd, nShow);   \
      }

#endif

There are also alqnx.h, alosx.h and almaccfg.h where the same stuff is defined.

This way Allegro devs avoided special static library like sdlmain.lib.

P.S.: ALLEGRO_WITH_MAGIC_MAIN and ALLEGRO_NO_MAGIC_MAIN are reserved
for user to allow forcing of specific main definition.

-- 
Roman Kyrylych (Роман Кирилич)


More information about the SDL mailing list