Good questions!
I'm not a huge fan of games programming ... I'm interested in...physics simulations [etc] |
You will find that a physics simulation is, basically, the same as a game. You have an event loop, input to respond to (at minimum, the ability to stop a simulation), things to track and display (particle systems, in particular, require some care), refresh and FPS tracking and adjustment, etc.
I just assumed [MSVC == Code::Blocks] |
LazyFoo explains both, IIRC. Each IDE is different, but the basics are the same: You must provide a include path, a library path, proper compiler switches, etc.
but I really like to understand what is going on at a lower level |
Good. That shows someone with intelligence.
[why link with SDL’s main() instead of just having SDL_init() do everything?] |
One word: cleanup.
The basis of RAII is that if you acquire a resource, you are responsible for cleaning it up. In C++ we use object lifetime for that. When a heavy object is created and initialized, its destructor will clean up for it. This keeps things clean.
When it comes to a basic executable, however, there are fewer avenues for doing this. SDL is designed to work for C or C++, so, lowest common denominator == take over main(). It probably has a hook on atexit() too.
There is also the possibility that there are initializations going on there that have nothing to do with SDL_init(). There are always structures behind the scenes that make things go, and with SDL’s extensibility, these things should be ready to use by an extension’s behind-the-scenes stuff
before SDL_init() is called. (I’m not saying this is the way it is, but it is a potential reason — I have not looked at SDL sources.)
The reason that taking over main() is common and desireable is not just that it is low-hanging fruit — it is about the
only simple method available cross-platform
and cross-compiler.
With MSVC, and on Linux with GCC, for example, you can easily declare your own entry point. The way you do this is different for each compiler. However, once you start moving from your standard Linux and Windows, these things don’t work as easily, nor do they guarantee the same behavior on different systems. This is because different systems have their own startup code, and each one is targeted for that specific system.
At this point we are starting to get into a lot of worms that SDL’s author(s) don’t really care for. Simply taking over main means that it works everywhere, with minimal effort.
Hope this helps. :O)