41
41
* This is also where an app can be configured to use the main callbacks, via
42
42
* the SDL_MAIN_USE_CALLBACKS macro.
43
43
*
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
45
45
* 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`.
47
50
*
48
51
* For more information, see:
49
52
*
66
69
* SDL does not define this macro, but will check if it is defined when
67
70
* including `SDL_main.h`. If defined, SDL will expect the app to provide the
68
71
* 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() .
70
73
*
71
74
* Please see [README/main-functions](README/main-functions), (or
72
75
* docs/README-main-functions.md in the source tree) for a more detailed
114
117
*
115
118
* \since This macro is available since SDL 3.2.0.
116
119
*/
117
- #define SDL_MAIN_AVAILABLE
120
+ #define SDL_MAIN_AVAILABLE 1
118
121
119
122
/**
120
123
* Defined if the target platform _requires_ a special mainline through SDL.
132
135
*
133
136
* \since This macro is available since SDL 3.2.0.
134
137
*/
135
- #define SDL_MAIN_NEEDED
138
+ #define SDL_MAIN_NEEDED 1
136
139
137
140
#endif
138
141
248
251
*
249
252
* \sa SDL_DECLSPEC
250
253
*/
251
- #define SDLMAIN_DECLSPEC
254
+ #define SDLMAIN_DECLSPEC SDL_DECLSPEC
252
255
253
256
#elif defined(SDL_MAIN_EXPORTED )
254
257
/* We need to export SDL_main so it can be launched from external code,
255
258
like SDLActivity.java on Android */
256
- #define SDLMAIN_DECLSPEC SDL_DECLSPEC
259
+ #define SDLMAIN_DECLSPEC SDL_DECLSPEC
257
260
#else
258
261
/* usually this is empty */
259
262
#define SDLMAIN_DECLSPEC
@@ -271,7 +274,7 @@ extern "C" {
271
274
272
275
/*
273
276
* 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
275
278
* "main" entry point. Instead, it will operate as a collection of
276
279
* functions that are called as necessary by the system. On some
277
280
* 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[]);
529
532
extern SDLMAIN_DECLSPEC int SDLCALL SDL_main (int argc , char * argv []);
530
533
531
534
/**
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() .
534
537
*
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().
539
546
*
540
547
* \since This function is available since SDL 3.2.0.
541
548
*
542
549
* \sa SDL_Init
550
+ * \sa SDL_RunApp
543
551
*/
544
552
extern SDL_DECLSPEC void SDLCALL SDL_SetMainReady (void );
545
553
@@ -550,13 +558,21 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetMainReady(void);
550
558
* mainFunction.
551
559
*
552
560
* 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 do
562
+ * *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.
555
570
*
556
571
* \param argc the argc parameter from the application's main() function, or 0
557
572
* if the platform's main-equivalent has no argc.
558
573
* \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).
560
576
* \param mainFunction your SDL app's C-style main(). NOT the function you're
561
577
* calling this from! Its name doesn't matter; it doesn't
562
578
* literally have to be `main`.
@@ -578,15 +594,15 @@ extern SDL_DECLSPEC int SDLCALL SDL_RunApp(int argc, char *argv[], SDL_main_func
578
594
*
579
595
* Generally, you should not call this function directly. This only exists to
580
596
* 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
582
598
* small as possible.
583
599
*
584
600
* Not all platforms use this, it's actual use is hidden in a magic
585
601
* header-only library, and you should not call this directly unless you
586
602
* _really_ know what you're doing.
587
603
*
588
604
* \param argc standard Unix main argc.
589
- * \param argv standard Unix main argv.
605
+ * \param argv standard Unix main argv. Should not be NULL.
590
606
* \param appinit the application's SDL_AppInit function.
591
607
* \param appiter the application's SDL_AppIterate function.
592
608
* \param appevent the application's SDL_AppEvent function.
0 commit comments