[SDL] SDL_main

Sam Lantinga slouken at libsdl.org
Mon Jun 10 09:41:25 PDT 2013

If you don't want SDL to redefine your main function, just
define SDL_MAIN_HANDLED before you include SDL.h, and then
call SDL_SetMainReady() before you call SDL_Init().

The reason it's there is, as people mentioned, there are some platforms
that don't use main() as the program entry point, or there needs to be some
custom runtime setup that happens before your program runs.

The best way to figure out what this is, is to look in SDL_main.h and see
what platforms this is needed on:
#if defined(__WIN32__) || defined(__IPHONEOS__) || defined(__ANDROID__)

On Windows, this is simply a convenience so you don't have to provide
WinMain().  If you have that, or you are using a library that needs it, you
don't need SDL to provide it.

On iOS, you need to set up an application delegate and start the event
system, otherwise your code will crash in really non-intuitive ways during
window creation.

On Android, the entry point is Java (unless you're completely using the
NDK) and your "main" function is called on a separate thread.

For the mobile platforms some people have proposed a callback based
application framework that better matches how the platform works rather
than trying to shoehorn it into the "single main function" application
model.  I'm certainly open to this, but would want to do this for SDL 2.1.

SDL is zlib licensed and you're welcome to tweak it however you want for
your needs.  If you've done something useful for other people, I would ask
that you share it with the community.


On Mon, Jun 10, 2013 at 9:26 AM, john skaller <skaller at users.sourceforge.net
> wrote:

> On 11/06/2013, at 1:51 AM, Sik the hedgehog wrote:
> > The real issue is coping with platforms that don't follow the standard
> > main() entry point, I pretty much refuse to work on anything that
> > can't work with it. Extremely annoying because the language standard
> > itself defines it, so the fact every platform has its own way to do it
> > pretty much defeats the whole point. Honestly I always looked at it
> > like a way to do lock-in.
> The C language standard contains a lot of stuff
> that is vaguely Unix centric and appropriate for the equipment
> that was around at the time.  Worse than main(), stdin, stdout.
> These make sense on terminals to PDP-11 based unix
> systems and not much else.
> However the C standard does define "hosted" and
> "non-hosted" systems and some stuff is only required
> on "hosted" systems.
> Actually, this is a good terminology. "Hosted SDL" defines
> a standard entry point, but "non-hosted" SDL doesn't.
> The non-hosted pure library may need extra support
> to work: the question is: what?
> My stuff is "Felix hosted" not "SDL hosted" but I still want
> SDL to work :)
> --
> john skaller
> skaller at users.sourceforge.net
> http://felix-lang.org
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20130610/c359d8ce/attachment.htm>

More information about the SDL mailing list