Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!phri!delftcc!sam From: sam@delftcc.UUCP (Sam Kendall) Newsgroups: net.lang.c Subject: Re: pointers to arrays of unknown size: (*p)[] Message-ID: <148@delftcc.UUCP> Date: Mon, 2-Jun-86 21:54:32 EDT Article-I.D.: delftcc.148 Posted: Mon Jun 2 21:54:32 1986 Date-Received: Wed, 4-Jun-86 08:19:20 EDT References: <140@delftcc.UUCP> <396@hadron.UUCP> <379@dg_rtp.UUCP> Organization: Delft Consulting Corp., New York Lines: 38 Summary: `T (*)[]' is legal in K&R; should it be in ANSI? Nice discussion by Wayne Throop. There are a couple of points I'd like to expand on. First, `T (*)[]' IS unambiguously legal according to K&R. See section 8.4. Joe, please send me mail if you still disagree. Second, it's an interesting question as to whether ANSI C should permit `T (*)[]'. (As Wayne points out, ANSI C prohibits it, in 3.5.3.2.) A pointer to a dimensionless array is a strange beast, and whether you allow it or not, some nice property is going to be violated. If you allow `T (*)[]', you can have a pointer to an object of unknown size. (Functions have no size, but they are not objects.) The following property is violated: if `p' is a pointer, then `p' points at either a function or an object with size. (Bitfields lack size as such, and you can't point to them.) But if you disallow `T (*)[]', you do worse, I think. Then there is only ONE type which cannot have a pointer-to type modifier attached to it. The following property is violated: if `T' is a type, then `T *' is also a type. The real conceptual difficulty, for me, is with the object of unknown size, not with the pointer to such a thing. If we have to have objects of unknown size, we might as well permit pointers to such objects. And do we have to have objects of unknown size? Yes! If we declare `extern int a[];', then `a' names such an object. Therefore ANSI C should allow pointers to arrays of unknown size. One final thought: the burden of proof should be on those who want to disallow the pointer to dimensionless array. When in doubt, allow it. And if you don't believe me, you're either more or less confused then I am. Jeez, this article reads like "C mysticism". No, seriously, it's a Good Thing to preserve easily-stated properties and orthogonalities and things like that. Anyone in doubt, read R. D. Tennent's excellent _Principles of Programming Languages_. ---- Sam Kendall { ihnp4 | seismo!cmcl2 }!delftcc!sam Delft Consulting Corp. ARPA: delftcc!sam@NYU.ARPA