The C99 and following C11 (see n1570, its latest draft, which is actually the standard in practice) standards define two flavors of C implementations (see C syntax wikipage) .
- hosted implementations (useful to code application software, e.g. on Linux, POSIX, or probably Windows) give you a standard C library (
libc
) - giving malloc
from <stdlib.h>
and printf
from <stdio.h>
etc etc..., and your program should define a main
function (of signature int main(int, char**)
or just int main(void)
). In a hosted implemention most functions are indirectly called from main
. As John Zwinck answered, some compilers give you a way to define functions to be called before main
in a very implementation specific way (and order). Notice that the libc
usually requires some implementation specific initialization and your main
is actually called from crt0 in an implementation specific way.
- freestanding implementations (useful to code system kernel software, or embedded software on micro-controllers) don't provide a full
libc
and do not define how the code can be run (and started). In that case your implementation should define how the software is run. In practice you'll need some external (e.g. assembly) code to call functions from your code.
The GCC compiler accepts the -ffreestanding
flag to give you a freestanding implementation (otherwise it is hosted)
Notice that hosted implementations are permitted to compile some standard functions in a tricky and magic way (if you #include
the standard header defining them). See examples here.
Notice also that the standard is defining how main
works in a hosted implementation (§5.1.2.2. Hosted environment page 12 of n1570
). In particular main
is the only function where the lack of return
is the same as return 0;
(also the standard exit(3) function would end the program nearly as if returning from main
).
In practice your question is implementation specific.