Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!mcnc!rti-sel!dg_rtp!throopw From: throopw@dg_rtp.UUCP (Wayne Throop) Newsgroups: net.lang.c Subject: Re: C'mon, guys! Message-ID: <398@dg_rtp.UUCP> Date: Sat, 14-Jun-86 14:57:37 EDT Article-I.D.: dg_rtp.398 Posted: Sat Jun 14 14:57:37 1986 Date-Received: Sun, 15-Jun-86 04:23:58 EDT References: <200@pyuxv.UUCP> <1181@ncoast.UUCP> <350@dg_rtp.UUCP> Lines: 50 > gilbert@aimmi.UUCP (Gilbert Cockton) > * given an array of dimensions a x b x c .. x n, > the array name is a pointer to array[0][0][0]..[0] Not quite. It isn't quite right to say that the array name "is" a pointer... this is what causes all the confusion. The array name, when *evaluated*, *yields* an address (except when the object of "sizeof"). Note that here I am using the term "address" to mean a non-lvalue address expression, and "pointer" to mean an lvalue address expression. Using this terminology, arrays are *never* pointers (except the usually cited kludge of an array formal argument.) > * the only time this is any real use if when passing arrays by reference > as `array' is easier and safer to write than > > &(array[0][0][0]..[0]) > > as you don't need to bear the array dimensions in mind. Huh? Since the operation e1[e2] is *defined* in C to be (*(e1+e2)), the fact that an array name evaluates to the address is used *even* *when* *an* *array* *is* *subscripted*. I'm not sure just what you are unclear about. It seems to me that most people are confused on two points: 1) They think that the fact that pointers and arrays can each be indirected and subscripted means that they are "the same thing". This is not the case. They both yeild address values when evaluated (except when object of sizeof), but they are describing an entirely different runtime storage arrangement. 2) If they are unconfused on point (1), they think that arrays of unknown size are pointers. This is *not* the case. This mistake is probably due to the fact that array formal arguments are equivalent to pointers, but this is a special case exception and does *not* make them equivalent in the general case. If you get straight these things: - how pointers/arrays are *evaluated* - what *runtime storage* their declaration implies - what *operations* can be done on addresses, and how subscripting is defined in terms of address arithmetic then you have a chance of understanding arrays and pointers in C. Most people are confused on one or more of these points. -- Wayne Throop !mcnc!rti-sel!dg_rtp!throopw