[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Is it perfectly to pass argv[] this way to function ?



On Tuesday 21 May 2002 04:31 am, Deepak Kotian wrote:
> Hi,
>
> Please check the code segment.
> /*************code start ****/
> #include <stdio.h>
> int func1(char **a_argv){
>  while (*a_argv!=NULL)
>  printf("\n%s", *a_argv++);
>  return(0);
> }
>
> int main(int argc, char *argv[]){
>  func1(&argv[0]);
> }
> /*************code end ****/
>
> This func1 function prints all the arguments with no problem, because
> main() is probably always on stack, so it works probably.
> Do anyone see any problem, if one passes argv[] this way ? Will there be
> portability issues, like on other UNIX flavors,etc.
>
> Please let me know.
>
> Thanks and Regards
> Deepak

It might work, but I'd say it's probably more standard and more portable to 
use standard argc to parse them.  It doesn't add much in the way of code, so 
where's the harm in using it?

P.S. Sorry, for some odd reason I'd pressed send before I intended to with 
the last one...


-- 
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: