arrays of pointers - NOVICE QUESTION!( Be forwarned ! )

Guy Harris guy at auspex.auspex.com
Tue Jun 6 04:02:31 AEST 1989


>The first and the second declarations are identical for all normal uses
>as long as you leave the size of the array out i.e.
>char *foo[]    ==     char **foo

Wrong!  The first and the second declarations are identical only when
used to declare a formal argument to a procedure.

>The ** stands for "pointer to pointer", and since the first pointer
>can be temporarily incremented using an "index", this pointer could
>as well be a pointer to an array of pointers. The difference is
>syntactical -- char *foo[] may be used in formal declarations/parameters
>only!

Wrong.

	extern char *foo[];

is perfectly legitimate, for example, and is a declaration of an array
of pointers to "char" that is defined elsewhere.  The *definition* has
to specify a size for the array, but the *declaration* doesn't.

>Also, the char *argv[] works, the char **argv doesn't, on my machine
>(Speaking of main(argc, argv), that is...) This might be a bug in the
>* ancient * compiler I use.

"Might be a bug"?  It definitely *is* a bug!  The "char **argv" is a
perfectly legitimate declaration, and if the compiler you use can't handle
it, it's broken (and wouldn't be able to cope with a *lot* of code out
there).



More information about the Comp.lang.c mailing list