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.h in the same file as your main function πŸŽ€
  • 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's argc. yes, the real one. no cap.
  • argv β€” an ANSI-C style main function's argv. 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 stuff SDL_main, don't skip the SDL_main.h include, 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