pointers to arrays of unknown size: (*p)[]
Wayne Throop
throopw at dg_rtp.UUCP
Sun Jun 1 07:35:32 AEST 1986
> jsdy at hadron.UUCP (Joseph S. D. Yao)
>> sam at delftcc.UUCP (Sam Kendall)
>> ... type formal[][]; "is adjusted to read" type (*formal)[];
>>This second type is "pointer to array of unknown length".
>
> Sam, this is not legal, has never been legal, and (pray God) will
> never be legal.
Well, sort of. K&R don't mention it. Harbison and Steele *seem* to
allow it. And the ANSI draft explicitly disallows it. But, many
compilers (and lint) allow it, and it does make the type notation in C
more nearly orthogonal and rational.
Let's look at what would happen if declarations of the form (*p)[] were
unambiguously legal.
> tell me: what do arrname[1] or *++ptr reference????
They don't reference anything at all. In particular, the calculation of
(p+n), (where p is declared as above, and n is an integer) cannot be
done, because the size of *p is unknown. Well, you say. There you are,
you say. Can't be did, you say. Not quite, I say. There are two
obvious examples of pointers in C which cannot participate in arithmetic
operations and the denotation type of which is of unknown size.
Pointer-to-function and pointer-to-void. So, a pointer declared with
(*p)[] would simply be another case of a pointer type where (sizeof *p)
and (p+n) would be illegal. (*p), and (*p)[n], and so on, would still
be quite legal.
So, while I agree that having arrays of things of unknown size is not
very meaningful, I'd say that having pointers to things of unknown size
is a venerable tradition in C, with (*p)() being the eldest example.
As I say, ANSI currently outlaws (*p)[]. But Harbison and Steele seem
to allow for it, lint currently allows it, and most current compilers
allow it. I would say that allowing (*p)[] is not much more radical
than allowing (*p)(), or (*p)[10].
--
Wayne Throop <the-known-world>!mcnc!rti-sel!dg_rtp!throopw
More information about the Comp.lang.c
mailing list