Re: main(int argc, char *argv[])
- From: Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx>
- Date: Fri, 29 Apr 2005 23:43:50 +0200
David Resnick wrote:
Michael Mair wrote:
David Resnick wrote:
Recursively calling main is a bit funky. Why not have main call
some
other function (which takes no arguments) which is then used for the recursion?
Anyway, you could always call main later with main(0,NULL). Or if you want, you could squirrel away (in a static) the original argc and argv and reinvoke main with them later.
Not exactly. argv[argc] must be NULL, i.e. you need main(0, p), where *p==NULL.
Um, why? I agree with what you say when main is originally invoked by the implementation. If invoked recursively and one no longer cares about using argc or argv why is main(0,NULL) not acceptable? In fact, if one is recursively invoking main (probably a bad idea), having argv be NULL seems like one reasonable way to indicate this is not the original invocation.
Hmmm, probably just because I hate breaking calling conventions; I only thought of that but not about the specific situation... Apart from that, the only time when I had seen a slightly justified(*) recursive call of main() was for something like "if (argc) main(argc-1, argv+1);" However, thinking about it once again, you are right -- most people do not rely on, let alone use, argv[argc]==NULL, so we might abuse the second argument to flag a recursive call (I still do not like it, though).
Regards Michael ____ (*) The small amount of justification came from a code length limit and an otherwise clear structure... :-) -- E-Mail: Mine is an /at/ gmx /dot/ de address. .
- References:
- main(int argc, char *argv[])
- From: Sokar
- Re: main(int argc, char *argv[])
- From: David Resnick
- Re: main(int argc, char *argv[])
- From: Michael Mair
- Re: main(int argc, char *argv[])
- From: David Resnick
- main(int argc, char *argv[])
- Prev by Date: Re: return a string
- Next by Date: re:return a string
- Previous by thread: Re: main(int argc, char *argv[])
- Next by thread: Re: main(int argc, char *argv[])
- Index(es):
Relevant Pages
|