SDL_main(3)
π SDL_main π
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where today's main character is SDL_main β An app-supplied function for program entry. yes that's the whole vibe, let's go π«Ά
β¨ SYNOPSIS β¨
#include <SDL3/SDL_main.h>
int SDL_main(int argc, char *argv[]);
πΈ DESCRIPTION πΈ
okay so here's the tea: you do NOT write this function yourself. like, ever. apps should write a totally normal, standard ANSI-C main function instead, and let SDL handle the chaos behind the scenes. π
and here's why that matters β if SDL needs to sneak some startup code in before main runs, or if the platform literally doesn't _use_ a function called "main" at all, SDL does some macro magic to redefine main into SDL_main and hands you its own main instead. iconic behavior honestly β¨
so like, the rules:
- include
SDL_main.hin the same file as yourmainfunction π - and do not use that symbol for anything else in that file, because it might get redefined and then everything is on fire π
also important: this function is only provided by the app if it isn't using SDL_MAIN_USE_CALLBACKS. so like, pick a lane bestie π
and ngl, program startup is a surprisingly complex topic. fr fr. please go read [README-main-functions](README-main-functions) β or docs/README-main-functions.md in the source tree β for the full deep-dive explanation. it's giving required reading π
π FUNCTION PARAMETERS π
argcβ an ANSI-C style main function'sargc. yes, the real one. no cap.argvβ an ANSI-C style main function'sargv. also the real one. π¦
β RETURN VALUE β
returns an ANSI-C main return code, bestie. so like β generally 0 is considered successful program completion, and small non-zero values are considered errors. that's the whole mood. periodt. π
π₯ THREAD SAFETY π₯
this is the program entry point. like, the literal entry point. main character energy, obviously π
π AVAILABILITY π
this function is available since SDL 3.2.0. so if you're on something older... bestie. π
lowkey reminder: don't name your own stuffSDL_main, don't skip theSDL_main.hinclude, and definitely don't do both wrong at once π
okay that's the whole page, you ate it, go write a main like a normal person and let SDL do its little macro thing π
Simple Directmedia Layer Β· SDL 3.4.18 Β· SDL_main(3) β mwah, see you in the next manpage bestie πβ¨
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms