pointers to arrays of unknown size: (*p)[]

Sam Kendall sam at delftcc.UUCP
Tue Jun 3 11:54:32 AEST 1986


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 at NYU.ARPA



More information about the Comp.lang.c mailing list