Re: Why does execution start at main()?
From: Wendy E. McCaughrin (wemccaug_at_bluestem.prairienet.org)
Date: 05/12/04
- Next message: Jack Klein: "Re: De-referencing pointer to function-pointer"
- Previous message: Peter Nilsson: "Re: Printing "hello , wolrd" with out using semicolon"
- In reply to: Malcolm: "Re: Why does execution start at main()?"
- Next in thread: Leor Zolman: "Re: Why does execution start at main()?"
- Reply: Leor Zolman: "Re: Why does execution start at main()?"
- Reply: Martin Dickopp: "Re: Why does execution start at main()?"
- Reply: Keith Thompson: "Re: Why does execution start at main()?"
- Reply: Nick Keighley: "Re: Why does execution start at main()?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 12 May 2004 03:36:01 +0000 (UTC)
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.
- Next message: Jack Klein: "Re: De-referencing pointer to function-pointer"
- Previous message: Peter Nilsson: "Re: Printing "hello , wolrd" with out using semicolon"
- In reply to: Malcolm: "Re: Why does execution start at main()?"
- Next in thread: Leor Zolman: "Re: Why does execution start at main()?"
- Reply: Leor Zolman: "Re: Why does execution start at main()?"
- Reply: Martin Dickopp: "Re: Why does execution start at main()?"
- Reply: Keith Thompson: "Re: Why does execution start at main()?"
- Reply: Nick Keighley: "Re: Why does execution start at main()?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]