Skip to content

Commit

Permalink
sdl
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 3, 2023
1 parent 0953258 commit 20eef74
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions docs/sdl.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ SDL 使用了一种技巧,通过宏定义将用户的 main 函数重命名为

下面是一段来自 pspdev 官网的示例代码
假如我们不加-SDLmain,只加-SDL2 直接编译,会报错`undefined refernce to 'main'`
这是十分奇怪的,因为我们我们显然定义了 main 函数。

注意到示例代码里不再有各种线程的注册和模块信息的指定,这正是因为 SDL 为我们提供的 main 函数帮助我们做到了这一点。
自建 main 函数这一过程的实现位于 SDL_main 库
这就要谈到 SDL 这个库的特性:SDL 使用了一种技巧,通过宏定义将用户的 main 函数重命名为 SDL_main。这样,当你在你的代码中写 main 函数时,预处理器实际上会将其重命名为 SDL_main。此后 SDL 会重新实现新的 main 函数,在其中调用 SDL_main 并在前后运行添加额外的处理流程。

注意到示例代码里不再有各种线程的注册和模块信息的指定,这正是因为 SDL 重新为我们定义的 main 函数能够帮我们做到这一点。
而自建 main 函数这一过程的实现位于 SDL_main 库

下面是摘录自 SDL_main.h 的一段注释

Expand All @@ -66,5 +69,5 @@ SDL 使用了一种技巧,通过宏定义将用户的 main 函数重命名为

下面是一段 SDL_main.c 的代码

- 需要 include SDL_main(在 SDL.h 中已经包含)
- 需要链接 SDL_main
需要 include SDL_main(在 SDL.h 中已经包含)
需要链接 SDL_main

0 comments on commit 20eef74

Please sign in to comment.