Koenig on pointers and arrays

Wayne Throop throopw at sheol.UUCP
Sun Jan 21 05:41:34 AEST 1990


>> From: cjoslyn at bingvaxu.cc.binghamton.edu (Cliff Joslyn)
>> "Only two things can be done to an array: determine its size and obtain
>> a pointer to element 0 of the array. [...]"
>> is the [.. above sentence ..] literally accurate?

> From: ark at europa.att.com (Andrew Koenig)
> If I really wanted to split hairs, I could have added that you can
> take the address of an array (but only in an ANSI compiler). [...]
> I don't think of taking the address of an array as being an
> array operation, though.  There's nothing special about the fact
> that it's an array.

But there IS something special about it, and that is the automatic
promotion of array names to rvalue addresses essentially everywhere.
Address-of is a reasonable exception, but it IS an exception, and
thus if "sizeof" is an array operation, so should address-of be.

Or maybe it is better to class it the other way around...

    In C there is only ONE array operation, that of yeilding the address
    of the first element of the array.  The subscript operation, which
    in other languages is an array operation, is in C a pointer arithmetic
    operation coupled with indirection.

In this view, neither sizeof or address-of is an array operation, but 
are operations that occur for any objects.
--
Wayne Throop <backbone>!mcnc!rti!sheol!throopw or sheol!throopw at rti.rti.org



More information about the Comp.lang.c mailing list