Mark said:
<mode pedantic = extreme>
It may smell like an array, and it may even look like one, but it
aint.
6.2.5(20)
.... Array types are characterized by their element type and by the
number of elements in the array....
The object returned by *alloc has neither of these characteristics.
</mode>
In static char *chars(void), n is an unsigned int used to count
characters, and x is a pointer to char. When the function has
found all of the characters in a word, it does:
x = malloc((n+1) * sizeof(char));
Assuming the allocation succeeds (and assuming the programmer
isn't spoofing anywhere), x now points to an array of n+1 members
of type char. Using "sizeof(char)" in the expression wasn't
necessary, but was intended to emphasize the element type.
The following statement
x[n] = '\0';
emphasizes the array nature of x. I could have written
*(x+n) = '\0';
to de-emphasize x's array nature.
In the function static char **words(void), n is an unsigned int
used to count the words (NUL-terminated arrays of type char)
produced by chars(); and x is a pointer to pointer(s) to chars.
When the function has found all of the words in a line, it does
x = malloc((n+1) * sizeof(char *));
Again, assuming the allocation succeeds, x points to an array of
pointers to words. The following statement,
x[n] = NULL;
emphasizes the array nature of x. I would have coded
*(x+n) = NULL;
if I'd wanted to downplay the array aspect.
In both functions, the number and type of members /is/ known. The
type is known (and specified) at compile time; and the number is
determined at execution time.
If we decide that in order for there to be an array, we must
inform the compiler of the number of elements, then there is a
great deal of corrective work to be done on the standard; and we
should probably drop all references to VLAs. I'm of the opinion
that while the number of elements does need to be known, it
doesn't need to be known at compile time.
BTW, Mark, have you completed your relocation? (Sorry I couldn't
contribute a bottle of wine for your housewarming!)