Chris ( Val ) wrote:
> On Mar 21, 9:03 pm, Philip Potter <p...@[EMAIL PROTECTED]
> wrote:
>> Hal Vaughan wrote:
>>> So
>>> char *argv[]
>>> and
>>> char **argv
>>> are essentially the same?
>> They are *exactly* the same in a parameter list.
>>
>> Elsewhere the difference is clear - one is an array of 'char *'s, and
>
> Don't you mean: "a pointer to an array of char*" ?
No, I don't. The magical cdecl program tells me:
cdecl> declare foo as pointer to array of pointer to char
Warning: Unsup****ted in C -- 'Pointer to array of unspecified dimension'
(maybe you mean "pointer to object")
char *(*foo)[]
The last line above is the syntax which you would use if pointers to
arrays of unspecified dimension were sup****ted in C.
It also explains:
cdecl> explain char *argv[]
declare argv as array of pointer to char
To return to basics:
char x[10];
char *y;
char (*z)[10]
x is an array of 10 'char'. It is *not* a pointer, but in most contexts
it acts like one. In such a context, the pointer value which x "decays"
to is a pointer to x's first element, with the type of pointer-to-char
or 'char *'. (These contexts include array subscripting x[i], arithmetic
x+i, but exclude the 'sizeof x' and '&x').
y is a pointer to 'char'. It can also point to the first element of an
array of char. This means that the syntax for using x and y are very
similar, even though they are objects with different types.
If I assign y = x; then y now points to the first element of an array.
However y is still a 'char *', that is, it points to a 'char', not to an
array of char (a 'char []'). Although some people may sloppily now refer
to y as a "pointer to x" or "pointer to an array", it is strictly
pointing to x's first element, and it is a pointer to char.
z is a true pointer to an array of 10 'char'. If I assign z = &x; then z
points to the whole x array. Pointers to arrays are not commonly seen. I
can't think of a situation in which I have ever used one.


|