Path: utzoo!mnetor!uunet!husc6!rutgers!mcnc!rti!xyzzy!throopw From: throopw@xyzzy.UUCP (Wayne A. Throop) Newsgroups: comp.lang.c Subject: Re: Address of Array Message-ID: <502@xyzzy.UUCP> Date: 23 Dec 87 19:20:56 GMT References: <3420@tut.cis.ohio-state.edu> Organization: Data General, RTP NC. Lines: 43 > lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani) > Summary: do I have it right now? Yep. But I can't resist clarifying one little nit. Something in my upbringing, I think. > 2) The name of an array is a synonym for the address of > the first element of the array. This is only a CONVENIENCE > so you can write: > for (p = name; p < &name[NTHINGS]; p++); > instead of having to write: > for (p = &name[0]; p < &name[NTHINGS]; p++); This is *right*, sort of, but I wouldn't put it this way, and putting it this way gives me an itchy sensation I just have to scratch. The way I think of it is not that an array name is a synonym for the address of the first element of the array, but that any array object, when encountered in an expression, is converted to the address of the first element in the array (except when object of sizeof or '&' operators). Note: "is converted", not "is a synonym". This way of thinking about it handles arrays of arrays nicely, while the alternate requires one to consider aa[N] to be the "name" of an array, which is not quite right. A small nit, perhaps, but I think it helps to think of it this way. Further, this isn't so much a convenience as it is a direct fallout of the definition of the subscripting/address-arithmetic equivalence in C. Personally, I would have done it just the way Larry describes above, and define pointer arithmetic in terms of array subscripting. But K&R in their wisdom did the reverse: subscripting is defined in terms of pointer arithmetic. This means that an array object, when used in a subscripting expression, *MUST* be converted to the address of the first element of the array for the subscript operation to work at all. K&R just extended this to become the default situation: array objects in most expressions are converted as they are in subscript expressions. Again, a small nit, but [etc, etc]. -- There are some forms of insanity which, driven to an ultimate expression, can become new models of sanity. --- Bureau of Sabotage {Frank Herbert} -- Wayne Throop !mcnc!rti!xyzzy!throopw