Re: Why does execution start at main()?

From: Leor Zolman (leor_at_bdsoft.com)
Date: 05/12/04


Date: Wed, 12 May 2004 03:53:23 GMT

On Wed, 12 May 2004 03:36:01 +0000 (UTC), "Wendy E. McCaughrin"
<wemccaug@bluestem.prairienet.org> wrote:

>Malcolm <malcolm@55bank.freeserve.co.uk> wrote:
>: "Beni" <benipegu@hotmail.com> wrote in message
>: >
>: > I have been programming in C for about a year now. It sounds silly,
>: > but I never took the time to question why a C(or C++ or Java)
>: > program execution begins only at the main(). Is it a convention or is
>: > there some deeper underlying reason?
>: >
>: The name "main" is obviously just a convention - "start" or "begin" could
>: have been chosen just as easily.
>
>: In C++ "main" is a hangover from C, it would have been more logical to
>: define a special object (called "app" or something similar) which is
>: initialised at program start and destroyed on termination.
>
>: Execution has to start from somewhere, and having a reserved function name
>: is as good a method as any. There is the quirk that it is not possible to
>: call a C program from another C program - you have to change the callee's
>: "main" to "xmain" or something similar.
>
>No. Dan Pop gave the correct explanation. Execution does NOT start with
>main(), but with the C runtime ("crt") code which sets up a runtime
>environment for main(), e.g.,: initializing argc, argv and envp.

Well, for that matter, execution doesn't "start" with the crt, but
when you boot the computer. Give the guy a break ;-)
        -leor


Quantcast