Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!mcnc!rti-sel!dg_rtp!throopw From: throopw@dg_rtp.UUCP (Wayne Throop) Newsgroups: net.lang.c Subject: pointers to arrays of unknown size: (*p)[] Message-ID: <379@dg_rtp.UUCP> Date: Sat, 31-May-86 17:35:32 EDT Article-I.D.: dg_rtp.379 Posted: Sat May 31 17:35:32 1986 Date-Received: Sun, 1-Jun-86 08:41:28 EDT References: <140@delftcc.UUCP> <396@hadron.UUCP> Lines: 40 Summary: (*p)[] appealing sentence, out on bail > jsdy@hadron.UUCP (Joseph S. D. Yao) >> sam@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 !mcnc!rti-sel!dg_rtp!throopw