From 823b218051c2ba4f1b4d7ca3ab3f279d15222f01 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Tue, 8 Oct 2024 18:03:16 +0200 Subject: [PATCH] Simplify code to include SDL_main_impl.h in SDL_main.h Basically all platforms where SDL_main.h renames main() to SDL_main() use the platform-specific main() (or WinMain() or whatever) implementations in SDL_main_impl.h - and that renaming is enabled with: #if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE) \ || defined(SDL_MAIN_USE_CALLBACKS) #define main SDL_main #endif The only exception is Android, where main() *is* renamed, but SDL_main_impl.h isn't used, because SDL_main() is called from Java. So I think it's cleaner and less error-prone (for adding additional platforms that need SDL_main() in the future), to use the same check for including SDL_main_impl.h as is used for `#define main SDL_main` and only list the exceptions (currently Android) there explicitly. If new platforms like Android turn up, they can easily be added there by inserting "|| defined(SDL_PLATFORM_WEIRDPLATFORM)" right next to the Android check. See also https://github.com/libsdl-org/SDL/issues/11068#issuecomment-2399907535 --- include/SDL3/SDL_main.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/SDL3/SDL_main.h b/include/SDL3/SDL_main.h index ca82df73a8..63fbcf194b 100644 --- a/include/SDL3/SDL_main.h +++ b/include/SDL3/SDL_main.h @@ -562,11 +562,12 @@ extern SDL_DECLSPEC void SDLCALL SDL_GDKSuspendComplete(void); #include #if !defined(SDL_MAIN_HANDLED) && !defined(SDL_MAIN_NOIMPL) - /* include header-only SDL_main implementations */ - #if defined(SDL_MAIN_USE_CALLBACKS) \ - || defined(SDL_PLATFORM_WINDOWS) || defined(SDL_PLATFORM_IOS) || defined(SDL_PLATFORM_TVOS) \ - || defined(SDL_PLATFORM_3DS) || defined(SDL_PLATFORM_NGAGE) || defined(SDL_PLATFORM_PS2) || defined(SDL_PLATFORM_PSP) \ - || defined(SDL_PLATFORM_EMSCRIPTEN) + /* include header-only SDL_main implementations + * Note: currently Android is the only platform where we rename main() to SDL_main() + * but do *not* use SDL_main_impl.h (because SDL_main() is called from external Java code) + */ + #if ( defined(SDL_MAIN_USE_CALLBACKS) || defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE) ) && \ + !defined(SDL_PLATFORM_ANDROID) /* platforms which main (-equivalent) can be implemented in plain C */ #include