On Aug 31, 9:34 pm, stan <smo...@exis.netwrote:
James Kanze wrote:
On Aug 30, 4:48 pm, Marcel Müller <news.5.ma...@spamgourmet.org>
wrote:
pankaj do it wrote:
what is the difference between the main() function of c and c++
There is no difference. Both have the same signature. Both use
C linkage.
In C++, the linkage of main is implementation defined. It might
be "C++", it might be "C" or it might be something else
entirely.
Isn't this largly determined by the startup code as a
practical matter? If so, it seems that basically it's
implementation defined even in c.
Formally, the C++ or C program doesn't start until main has been
reached, but practically, yes... an implementation will
obviously have to define main in some way that it can be called
via the start-up code. (But of course, the start-up code is
part of the implementation.) As another poster pointed out, C
also allows main to be called (recursively) from within the
program, which introduces some additional constraints on it.
It's probably just a personal limitation, but I can't imagine
a reason to call main from anything other than startup code.
There are some interesting examples of using main recursively in
the IOCCC, but that's about it as far as I'm concerned as well.
Seems like any attempt to do so would need to diddle
implementation defined environment stuff to be effective. To
use Kernighan's phrase, am I suffering from a "poverty of
imagination"?
I can imagine any number of special things you could do by
calling main recursively. In every case, however, I can also
imagine a solution which wouldn't involve calling main
recursively which would be considerably more understandable and
easier to maintain.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34