Address of array

Wayne Throop throopw at dg_rtp.UUCP
Wed Mar 19 04:36:04 AEST 1986


> 	[...] C's treatment of array/function/struct addresses is
> 	inconsistant, confusing, and limiting.  
>
> I diagree violently (so what else is new?). The resolution of pointers
> and arrays is one of the *strengths* of C.

Actually, you disagree needlessly :-).  I said that things were treated
inconsistantly, not that array/pointer equivalence is a not-good idea.

> Admittedly there are a few glitches,

Ah, you've noticed that too, eh?

> such as when the sizeof operator is applied to an array. Ironically,
> this glitch was added to *help* the user.

Glitches added to help the user are still glitches.  And, in the end, I
question whether they actually help the user.

> Personally, when a formal
> parameter is declared as a local array, I would like to see sizeof
> return the same as if it was a global.

You too?  Good.  You listening, ANSI?

> 	In essence a small notational
> 	convenience was traded for a large consistancy headache.  I think the
> 	tradeoff was wrong, [...]
>
> All the compilers I've seen give a warning, but generate &array[0].

Let me clarify what small notational convenience and what consistancy
headache I am talking about here.  The notational convenience is that an
array name "means" the address of the first element of the array.  The
consistency headache is that then addressing (and "mentioning") of
arrays and other things (such as structs) does not behave similarly, and
it becomes impossible to (legally, formally) take the address of an
entire array (at least, without adding warts to the warts and making yet
another "glitch").

The idea of array/pointer equivalence would cause *much* fewer problems
if the question of notational convenience of passing arrays (by
reference) hadn't clouded the issue.  This led directly to the common
confusions about whether definitions of pointers reserve
space for the items pointed to (and as to whether array
declarations do, also), the confusion of whether a structure name
indicates the address of the structure or it's contents, the inability
to treat arrays by value (since you get a reference whenever the name of
the array is mentioned), and so on and on.

I am not arguing here from a "language purity" high horse.  I am saying
that actual experience with C and the type of errors that are commited
in the use of C make me think that the treatment of array and function
addressing (and the fact that these things are different from struct
addressing) has spread confusion.  Further, this confusion has made the
C language much harder to master then it "ought" to be, and has obscured
some of its strong points, such as array/pointer equivalence.

-- 
Wayne Throop at Data General, RTP, NC
<the-known-world>!mcnc!rti-sel!dg_rtp!throopw



More information about the Comp.lang.c mailing list