Re: main(int argc, char *argv[])



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.
.



Relevant Pages

  • Re: modifying the strings pointed to by argv
    ... The standard just says "argc and argv and the strings pointed to ... by the argv array shall be modi�able by the program." ... functions or for the recursion of main. ...
    (comp.lang.c)
  • Re: main(int argc, char *argv[])
    ... Michael Mair wrote: ... >> recursion? ... about using argc or argv why is mainnot acceptable? ...
    (comp.lang.c)