ptrs and arrays

Wayne Throop throopw at sheol.UUCP
Sat Nov 11 04:58:09 AEST 1989


> chris at mimsy.umd.edu (Chris Torek)
> But look at what you just said: operations on the *element type* of the
> array: not operations on the array as a whole.  Operations on these
> elements need pointers to the elements, not a pointer to the array.

Yes.  But the manipulations are hidden inside procedures or macros.
The manufacture of the address of the entity to be manipulated might
also be encapsulated, but if the "&" unary operator is to be used in
any reasonable way (which is what I meant by *partial* information
hiding... the addressability is not abstracted), then one must be
able to utter the type of the resulting expression, so that it can
(for example) properly be passed to routines which will manipulate
it (and which know the correct size).

I admit that there are ways of avoiding this problem.  For example,
encapsulating the address-of operation, and having it yeild void or
pointer-to-element-type.  For another, have the interface specify
a pointer-to-void in a prototype, so that a cast will occur automagically.

I admit this as I say... But I also think it would be cleaner to be
able to simply utter the "correct" type.  Marginally cleaner, but
cleaner nonetheless.  (Or maybe it IS "theless", but it's *still*
cleaner notwhithstanding.)      (or should that be irregardless....)

Just think of how often people wish the jmp_buf type were cleaner
in just this sort of way.


> Arrays often get short shrift in C, and I think this applies to information
> hiding as well.

Very definitely agreed.  And we all know how painful *that* can be.
--
Wayne Throop <backbone>!mcnc!rti!sheol!throopw or sheol!throopw at rti.rti.org



More information about the Comp.lang.c mailing list