Hm. This is one of the peculiarities in C.
Logically, declaring an array of unknown size containing pointers of some kind...
...is the same as allocating a pointer to a pointer, like:
Except for the char** not telling the compiler anything much of how you will use the pointer-pointer, other than for accessing some chars with two level pointer indirection.
No other storage is allocated than for one pointer. Except if one declares the variable statically with an initializer, like the following:
Quote:
Originally Posted by 14moose
Code:
char *animals[] = {
"cow",
"pig",
"horse"
};
|
In this case the compiler knows the size, and allocates an array of pointers, along with the char* initialized content and sets the pointers in the array to point out the "cow", "pig" and "horse" strings.
Lets say we declare:
Have we defined an array of 15 char pointers or have we declared a pointer to an array of 15 chars?
(there is one correct answer, but putting out the question shows the ambiguity between how pointers vs arrays work).
If one wants to allocate a pointer to an array of char pointers, without initializing it, then one should declare:
Thus clearly stating to the compiler not to initialize any char strings, nor any array of pointers to them, but just allocating a pointer for it.
If one declares an array of pointers without telling how big the array is, either with a specified nubmer of rows or implicit with an initializer filling in the contents, then the compiler don't know how to allocate the array of pointers.
One could argue that the compiler should treat a "char *a[];" the same as being just a "char **a;", but i suspect that allowing for declaring unbound arrays of pointers will only have the effect that an even bigger number of programs will occationally crash with a segmentation fault.