Edit: Billy beat me to the answer, but here's a bit more background
More directly, main is usually more a function of the standard library. The thing that calls main
isn't C, but rather the standard library. The OS loads the application, transfers control to the library's entry point (_start
in GCC), and the library ultimately calls main
. This is why the entry point for a windows application can be WinMain
, and not the usual. Embedded programming can have the same sort of thing. If you don't have a standard library, you have to write the entry point that the library normally provides (among other things), and you can name it whatever you want.
In the GCC toolchain, you can also replace the library's entry point with your own by using the -e
option. (For that matter, you can also remove the library entirely.)
Make your own:
int main(int argc, char *argv[])
{
#if defined(BUILD_UNIT_TESTS)
return main_unittest(argc, argv);
#endif
#if defined(BUILD_RUNTIME)
return main_run(argc, argv);
#endif
}
If you don't like ifdef
, then write two main modules that contain only main. Link one in for unit tests and the other in for normal use.