Skip to content

Commit

Permalink
docs/README-main-functions.md: reformatted Best Practices section.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Nov 28, 2024
1 parent 5cd188b commit d53241a
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions docs/README-main-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,32 @@ data, as this pointer will not be provided to your app again.
The SDL_AppResult value that terminated the app is provided here, in case
it's useful to know if this was a successful or failing run of the app.

##Summary and Best Practices

Always Include SDL_main.h in One Source File: When working with SDL, remember that SDL_main.h must only be included in one source file in your project. Including it in multiple files will lead to conflicts and undefined behavior.
## Summary and Best Practices

Avoid Redefining main: If you're using SDL's entry point system (which renames main to SDL_main), do not define main yourself. SDL takes care of this for you, and redefining it can cause issues, especially when linking with SDL libraries.
- **Always Include SDL_main.h in One Source File:** When working with SDL,
remember that SDL_main.h must only be included in one source file in your
project. Including it in multiple files will lead to conflicts and undefined
behavior.

Using SDL's Callback System: If you're working with more complex scenarios, such as requiring more control over your application's flow (e.g., with games or apps that need extensive event handling), consider using SDL's callback system. Define the necessary callbacks and SDL will handle initialization, event processing, and cleanup automatically.
- **Avoid Redefining main:** If you're using SDL's entry point system (which
renames `main` to `SDL_main`), do not define `main` yourself. SDL takes care
of this for you, and redefining it can cause issues, especially when linking
with SDL libraries.

Platform-Specific Considerations: On platforms like Windows, SDL handles the platform-specific entry point (like WinMain) automatically. This means you don't need to worry about writing platform-specific entry code when using SDL.
- **Using SDL's Callback System:** If you're working with more complex
scenarios, such as requiring more control over your application's flow
(e.g., with games or apps that need extensive event handling), consider
using SDL's callback system. Define the necessary callbacks and SDL will
handle initialization, event processing, and cleanup automatically.

- **Platform-Specific Considerations:** On platforms like Windows, SDL handles
the platform-specific entry point (like `WinMain`) automatically. This means
you don't need to worry about writing platform-specific entry code when
using SDL.

- **When to Skip SDL_main.h:** If you do not require SDL's custom entry point
(for example, if you're integrating SDL into an existing application or a
scripting environment), you can omit SDL_main.h. However, this will limit
SDL's ability to abstract away platform-specific entry point details.

When to Skip SDL_main.h: If you do not require SDL's custom entry point (for example, if you're integrating SDL into an existing application or a scripting environment), you can omit SDL_main.h. However, this will limit SDL's ability to abstract away platform-specific entry point details.

0 comments on commit d53241a

Please sign in to comment.