From: "Michael Kjörling" <michael@kjorling.se>
To: tuhs@tuhs.org
Subject: Re: [TUHS] where did "main" come from?
Date: Fri, 22 May 2020 20:01:49 +0000 [thread overview]
Message-ID: <5507c573-f458-4eec-8d15-fee211a3b76d@localhost> (raw)
In-Reply-To: <BC361958-C8A0-4F42-8E9D-A3E981749CCC@serissa.com>
On 22 May 2020 14:43 -0400, from stewart@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---libc-start-main-.html
[2]: https://blogs.oracle.com/linux/hello-from-a-libc-free-world-part-1-v2
--
Michael Kjörling • https://michael.kjorling.se • michael@kjorling.se
“Remember when, on the Internet, nobody cared that you were a dog?”
next prev parent reply other threads:[~2020-05-22 20:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-22 18:43 Lawrence Stewart
2020-05-22 20:01 ` Michael Kjörling [this message]
2020-05-22 21:52 ` Clem Cole
2020-05-22 22:00 ` Rob Pike
2020-05-22 23:33 ` Toby Thain
2020-05-22 23:58 ` Win Treese
2020-05-22 22:08 ` Charles Anthony
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5507c573-f458-4eec-8d15-fee211a3b76d@localhost \
--to=michael@kjorling.se \
--cc=tuhs@tuhs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).