4141 * This is also where an app can be configured to use the main callbacks, via
4242 * the SDL_MAIN_USE_CALLBACKS macro.
4343 *
44- * SDL_main.h is a "single-header library," which is to say that including
44+ * ` SDL_main.h` is a "single-header library," which is to say that including
4545 * this header inserts code into your program, and you should only include it
46- * once in most cases. SDL.h does not include this header automatically.
46+ * once in most cases. `SDL.h` does not include this header automatically.
47+ *
48+ * If you want to include `SDL_main.h` but don't want SDL to redefine main(),
49+ * you should define SDL_MAIN_HANDLED before including `SDL_main.h`.
4750 *
4851 * For more information, see:
4952 *
6669 * SDL does not define this macro, but will check if it is defined when
6770 * including `SDL_main.h`. If defined, SDL will expect the app to provide the
6871 * proper entry point for the platform, and all the other magic details
69- * needed, like manually calling SDL_SetMainReady.
72+ * needed, like manually calling SDL_RunApp() or SDL_SetMainReady() .
7073 *
7174 * Please see [README/main-functions](README/main-functions), (or
7275 * docs/README-main-functions.md in the source tree) for a more detailed
114117 *
115118 * \since This macro is available since SDL 3.2.0.
116119 */
117- #define SDL_MAIN_AVAILABLE
120+ #define SDL_MAIN_AVAILABLE 1
118121
119122/**
120123 * Defined if the target platform _requires_ a special mainline through SDL.
132135 *
133136 * \since This macro is available since SDL 3.2.0.
134137 */
135- #define SDL_MAIN_NEEDED
138+ #define SDL_MAIN_NEEDED 1
136139
137140#endif
138141
248251 *
249252 * \sa SDL_DECLSPEC
250253 */
251- #define SDLMAIN_DECLSPEC
254+ #define SDLMAIN_DECLSPEC SDL_DECLSPEC
252255
253256#elif defined(SDL_MAIN_EXPORTED )
254257/* We need to export SDL_main so it can be launched from external code,
255258 like SDLActivity.java on Android */
256- #define SDLMAIN_DECLSPEC SDL_DECLSPEC
259+ #define SDLMAIN_DECLSPEC SDL_DECLSPEC
257260#else
258261/* usually this is empty */
259262#define SDLMAIN_DECLSPEC
@@ -271,7 +274,7 @@ extern "C" {
271274
272275/*
273276 * You can (optionally!) define SDL_MAIN_USE_CALLBACKS before including
274- * SDL_main.h, and then your application will _not_ have a standard
277+ * ` SDL_main.h` , and then your application will _not_ have a standard
275278 * "main" entry point. Instead, it will operate as a collection of
276279 * functions that are called as necessary by the system. On some
277280 * platforms, this is just a layer where SDL drives your program
@@ -529,17 +532,22 @@ typedef int (SDLCALL *SDL_main_func)(int argc, char *argv[]);
529532extern SDLMAIN_DECLSPEC int SDLCALL SDL_main (int argc , char * argv []);
530533
531534/**
532- * Circumvent failure of SDL_Init() when not using SDL_main() as an entry
533- * point.
535+ * Informs SDL that the app has performed all the due diligence required when
536+ * providing its own entry point instead of using SDL_main() .
534537 *
535- * This function is defined in SDL_main.h, along with the preprocessor rule to
536- * redefine main() as SDL_main(). Thus to ensure that your main() function
537- * will not be changed it is necessary to define SDL_MAIN_HANDLED before
538- * including SDL.h.
538+ * Apps that don't use SDL_main() should call SDL_SetMainReady() before
539+ * calling SDL_Init(), otherwise SDL_Init() may fail on some platforms.
540+ *
541+ * If your app provides its own entry point, consider using SDL_RunApp(),
542+ * which will perform all of the required platform-specific setup for you and
543+ * is generally more portable and reliable than performing all the setup on
544+ * your own. When using SDL_RunApp(), you do *not* need to call
545+ * SDL_SetMainReady().
539546 *
540547 * \since This function is available since SDL 3.2.0.
541548 *
542549 * \sa SDL_Init
550+ * \sa SDL_RunApp
543551 */
544552extern SDL_DECLSPEC void SDLCALL SDL_SetMainReady (void );
545553
@@ -550,13 +558,21 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetMainReady(void);
550558 * mainFunction.
551559 *
552560 * You can use this if you want to use your own main() implementation without
553- * using SDL_main (like when using SDL_MAIN_HANDLED). When using this, you do
554- * *not* need SDL_SetMainReady().
561+ * using SDL_main() (like when using SDL_MAIN_HANDLED). When using this, you
562+ * do *not* need to call SDL_SetMainReady().
563+ *
564+ * If `argv` is not NULL, SDL will pass it forward to `mainFunction` as-is.
565+ * Otherwise, if `argv` is NULL, the behavior is platform-dependent: on some
566+ * platforms, SDL may try to get the command-line arguments for the current
567+ * process and use those instead, and on others it may fall back on a simple
568+ * dummy argv. Either way, SDL ensures that the final argv passed to
569+ * `mainFunction` is never NULL.
555570 *
556571 * \param argc the argc parameter from the application's main() function, or 0
557572 * if the platform's main-equivalent has no argc.
558573 * \param argv the argv parameter from the application's main() function, or
559- * NULL if the platform's main-equivalent has no argv.
574+ * NULL if the platform's main-equivalent has no argv (in which
575+ * case SDL will override it in a platform-specific manner).
560576 * \param mainFunction your SDL app's C-style main(). NOT the function you're
561577 * calling this from! Its name doesn't matter; it doesn't
562578 * literally have to be `main`.
@@ -578,15 +594,15 @@ extern SDL_DECLSPEC int SDLCALL SDL_RunApp(int argc, char *argv[], SDL_main_func
578594 *
579595 * Generally, you should not call this function directly. This only exists to
580596 * hand off work into SDL as soon as possible, where it has a lot more control
581- * and functionality available, and make the inline code in SDL_main.h as
597+ * and functionality available, and make the inline code in ` SDL_main.h` as
582598 * small as possible.
583599 *
584600 * Not all platforms use this, it's actual use is hidden in a magic
585601 * header-only library, and you should not call this directly unless you
586602 * _really_ know what you're doing.
587603 *
588604 * \param argc standard Unix main argc.
589- * \param argv standard Unix main argv.
605+ * \param argv standard Unix main argv. Should not be NULL.
590606 * \param appinit the application's SDL_AppInit function.
591607 * \param appiter the application's SDL_AppIterate function.
592608 * \param appevent the application's SDL_AppEvent function.
0 commit comments