[FAQ] difference(s) between char** argv and char* argv[]

[FAQ] difference(s) between char** argv and char* argv[]

Post by Arthur J. » Fri, 05 Sep 2003 10:05:23



Yes. They're EXACTLY THE SAME THING. You have already been told this,
several times, modulo Tisdale's muddyings. [Ignore him.]

bar_t foo ( baz_t quux[] );

is exactly equivalent to

bar_t foo ( baz_t *quux );

in all respects.

The difference between p[] and *p comes OUTSIDE function prototypes,
where, for example,

extern int arr[];

declares 'arr' to be of type 'array[unspecified size] of int',
otherwise known as an "incomplete array type." Since the type
of 'arr' is incomplete, you can't, for example, take the 'sizeof'
the array. Contrariwise,

extern int *ptr;

declares 'ptr' to be of type 'pointer to int', and is not incomplete.
That is, you can use 'ptr' in the same way you'd use any pointer,
including, of course, taking the 'sizeof' it.

Just don't worry about these things until you have done the exercises
in the first five chapters of K&R (or equivalent). Then you can
start worrying about becoming a language lawyer. :-)

HTH,
-Arthur
 
 
 

[FAQ] difference(s) between char** argv and char* argv[]

Post by E. Robert » Fri, 05 Sep 2003 10:36:21


Please don't shout.


When was David told this?


You probably meant formal argument lists.
baz_t quux[] and baz_t* quux mean the same thing
in the *definition of function foo as well as in its declaration.


Please cite and quote the FAQ
that you believe is most relevant to David's question.

 
 
 

[FAQ] difference(s) between char** argv and char* argv[]

Post by Richard He » Fri, 05 Sep 2003 11:34:09


<snip>

It amounts to the same thing, in this case, so your objection is pointless.


In this code:

int main(int argc, char **argv)
{
return 0;
}

main() is declared, defined, and prototyped, all at once.

A prototype is merely a function declaration in which the types of all the
parameters are given. A definition is also a declaration.

--
Richard Heathfield : XXXX@XXXXX.COM
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.yqcomputer.com/ ~scs/C-faq/top.html
K&R answers, C books, etc: http://www.yqcomputer.com/
 
 
 

[FAQ] difference(s) between char** argv and char* argv[]

Post by dz197 » Sat, 06 Sep 2003 04:58:53


[snip]


no i am not trying to be a language lawyer. just trying to understand
the fundamental differences between the 2 so i don't use them in the
wrong way. now i wonder why C support 2 difference syntax when one is
enough...