[A83] Re: C(++) programming
[Prev][Next][Index][Thread]
[A83] Re: C(++) programming
On Tue, 18 Sep 2001, Andreas Winkelbauer wrote:
>
> > > you can never call main as far as i know! so a = main(); would be
> > > impossible because main is not a standard function.
> >
> > It is non-standard in that it is the the main function called by the
> > startup code to run your program, but other than that, I don't know of
> > anything really unique about it.
>
> what about returning a value to the OS (if there is one)? is this possible
> in other functions too?
Actually, it often is; there is usually a library function exit() which
can be used to exit and return a value to the OS from any function.
But I don't suppose that's what you were referring to. The reason main
can return stuff to the OS (when it uses return) is not because a return
in main is compiled any differently than a return in any other function.
Instead, it can do that because the startup code calls main to run the
program, and returns its value as the return code to the OS (to
oversimplify a bit, it's because the startup code itself does something
like "returncode = main(argc, argv);").
In at least some cases, the convention for returning values to the OS is
the same as that for the return value for a function, so even if main
really were the initial running point of your program (i.e. you had no
startup code) the result would still be the same, as then the OS would be
calling your program more or less like a function.
References: