On 22 May 2020 14:43 -0400, from stewart(a)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
[1] 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
place.
It looks like at least glibc uses _start as the actual entry point
[2]. 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.
[1]:
https://refspecs.linuxbase.org/LSB_3.1.0/LSB-generic/LSB-generic/baselib---…
[2]:
https://blogs.oracle.com/linux/hello-from-a-libc-free-world-part-1-v2
--
Michael Kjörling •
https://michael.kjorling.se • michael(a)kjorling.se
“Remember when, on the Internet, nobody cared that you were a dog?”