The Allegro Wiki is migrating to github at https://github.com/liballeg/allegro_wiki/wiki
END OF MAIN
The END_OF_MAIN macro is needed to ensure cross-platform compability.
It is not needed.
It is needed because Windows uses WinMain function as entry point instead of main. The END_OF_MAIN macro makes Windows accept linking against a regular main. First, the END_OF_MAIN macro uses #define main _mangled_main to rename main to _mangled_main, in order to avoid conflicts about the symbol main. Then it creates a WinMain function which calls the _mangled_main function. It's done in such a way that both main() and main(int argc, char** argv) are supported.
It is not needed. You can enable a magic main function with the --enable-magicmain switch to configure, but this is hardly useful.
In OS X, the thread which receives OS events must be the main thread. In Allegro's design, events are received asynchronously to the main program. So there must be an extra thread receiving events - and in the case of OS X this must be the main thread. Since the main thread is the events thread, user code run needs to run in an alternate thread, which is created before the user main function is entered. #define main _mangled_main is used to rename the user main, and Allegro will start _mangled_main as a new thread. END_OF_MAIN then creates a new real main function to handle the events thread.
- The END_OF_MAIN macro does not have a semicolon after it. While most compilers accept END_OF_MAIN();, it is technically incorrect, and may result in a warning on some compilers.