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



jmccloughlin@xxxxxxxxxxx (Sokar) writes:
> I have my main function set up as
>
> int main(int argv, char *argv[])
>
> so taht i can read in a variable which is passed to the program on the
> command line. The problem is that main calls other functions and some
> of them need to start jump to the start of main. If my main setup was
> just int main() this would be no problem, i could just call main();

As others have mentioned, if you really want recursion it's best to
have a separate recursive function that you call from main. It's
legal to call main recursively, but the new invocation will (probably)
have no way of knowing that it's not the original one, so it will try
to process the command-line arguments all over again. (You can pass
in extra information in the parameters, or you can use a static
variable, but both approaches are kludges.)

But since you said you need to "jump to the start of main", I suspect
what you really need is not recursion but simply a loop. Recursion is
a powerful tool, but you shouldn't use it unless it's appropriate.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • chown/chgrp -R : Permission denied
    ... When I use an local admin account to recursively use chown and chgrp ... command, presumably because command cannot descend into the ... not all at once using recursion? ...
    (comp.unix.questions)
  • Re: ld : cannot find entry symbol _start Linux gcc 2.96
    ... that your actual command line ... project is using extremely weird naming convention. ... generated dependency files, your project is using "normal" naming ... In order to understand recursion you must first understand recursion. ...
    (comp.os.linux.development.apps)
  • Re: Configure process error in compilation of libxml2
    ... Because it reverses the logical flow of conversation. ... re-run the command "by hand". ... In order to understand recursion you must first understand recursion. ...
    (comp.unix.aix)
  • Re: find command : only print the file name matches
    ... > I am using this find command to find a string, ... I wonder how to manipulate the command so that only the ... Then I thought you'd be interested in doing just with a recursive grep :-) ... Mind, that in your case, mixing the *.h and the recursion limits the ...
    (comp.unix.shell)
  • Re: [SLE] Copying files
    ... >> can set appropriate flags in find to prevent recursion. ... > listing to give it to the command line, it fails, because the commnad ... And perhaps on a bunch of them if the bunch is ... it does work on a single file. ...
    (SuSE)