[TUHS] where did "main" come from?
michael at kjorling.se
Sat May 23 06:01:49 AEST 2020
On 22 May 2020 14:43 -0400, from stewart at serissa.com (Lawrence Stewart):
> C main programs define “main”.
I don't have a ready answer to your question where that name came
from, but it's worth remembering (and easy to forget) that main()
isn't the actual starting point of execution of a C program. Rather,
the starting point is a function within the C library, which does some
early setup work and then ultimately calls main() and takes care of
passing the return value from main() back to the operating system (see
 for Linux, for example).
This is perhaps most obvious in C programs for Microsoft Windows,
which don't have the traditional main() but do have a WinMain() in its
It looks like at least glibc uses _start as the actual entry point
. In turn, on x86-64 (and very likely also on other architectures),
that calls __libc_start_main(), which in turn calls main() via a
function pointer passed to it.
Michael Kjörling • https://michael.kjorling.se • michael at kjorling.se
“Remember when, on the Internet, nobody cared that you were a dog?”
More information about the TUHS