OT: Started a blog about D, OpenGL and SDL

Mike Parker aldacron71 at yahoo.com
Fri Jan 26 10:30:29 PST 2007


Anders F Björklund wrote:
> Mike Parker wrote:

> On Win32 and MacOS, SDL does a little trickery before the real main
> by redefining "main" with a macro (!) that will call a SDL function:
> 
> /* The application's main() function must be called with C linkage,
>    and should be declared like this:
> #ifdef __cplusplus
> extern "C"
> #endif
>         int main(int argc, char *argv[])
>         {
>         }
>  */
> #define main    SDL_main
> 
> /* The prototype for the application's main() function */
> extern C_LINKAGE int SDL_main(int argc, char *argv[]);

Exactly. I believe this was the original intent of SDL_main, but it got 
cluttered with other garbage as well.

> 
> This "SDL_main" does some SDL setup, and then calls the real "main"
> with the arguments filtered (as some arguments are handled by SDL)
> 
> For Win32 you can fake this SDL_main by reproducing it in D, but
> for the regular MacOS driver it is written in Objective-C (not C)...

For Win32, you can just skip it completely. I have a C framework I put 
together that uses SDL and doesn't even link in SDL_main. That's why 
DerelictSDL has no issues on Windows. All SDL_main does there is 
redirect stdout & stderr, call SDL_Init with the NO_PARACHUTE flag, and 
call ddhelp.exe for some reason, all of which can be done without.

I looked over the Mac version of SDL_main a while ago, but I didn't 
really grok it. What exactly does it do that is required to run an SDL 
app? Why can we not do without it on Mac? That's what I'm curious about.



More information about the Digitalmars-d-announce mailing list