Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Thomas David Rivers Newsgroups: comp.lang.c++ Subject: Re: Problem with array objects Date: Wed, 01 Jun 2011 09:57:16 -0400 Organization: Aioe.org NNTP Server Lines: 115 Message-ID: <4DE6453C.7080307@dignus.com> References: <805Dp.26220$7H.26163@newsfe08.ams2> <4DDD0AE0.9080001@dignus.com> <4DDD34A8.6030005@dignus.com> <4VdDp.17340$h35.4417@newsfe19.ams2> <4DDD9893.9060502@dignus.com> <4DDE50C0.1080402@dignus.com> <8ktDp.17767$h35.800@newsfe19.ams2> <4DDE9FCD.9050005@dignus.com> <4DDFA87C.9060808@dignus.com> <4DDFF65B.8010007@dignus.com> <21UDp.11231$5C7.1331@newsfe10.ams2> <4DE03514.7080802@dignus.com> <4DE10DA2.9050201@dignus.com> <4DE19579.1060300@dignus.com> <4DE252BD.8060100@dignus.com> <4DE2D8FA.6@dignus.com> <7fPEp.12138$El6.500@newsfe21.ams2> <4DE4F114.9040801@dignus.com> NNTP-Posting-Host: 5vmandCOS2XnoG0+Ic8whg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.13) Gecko/20061027 X-Accept-Language: en-us, en X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:5967 Paul wrote: > > "Thomas David Rivers" wrote in message > news:4DE4F114.9040801@dignus.com... > >> Paul wrote: >> >>> >>> Yes I agree. >> >> >> >> That's great! >> >> So - now, given our understanding that an lvalue reference >> to an array name is converted to be a pointer to the first element >> of the array, we can examine things like array indexing (which >> is really cool) and multiple dimension arrays... >> >> I propose we take a look at array indexing... would that be interesting? >> > I agree given that an array name is converted to a pointer to the > array and not ONLY to a first element of the array. > Can you agree that an array name converted to a pointer points to an > array? Oh - I'm sorry, but I can't, and when we get into how indexing works and how arrays with multiple dimensions work I hope to motivate the argument of why that isn't a correct characterization... but, that comes later. That is, we need to be quite careful with the types of things; or the entire mess comes crumbling down. You see - there is the idea of a pointer to an array, and that is quite different from the idea of a pointer to an element of an array. One can imagine that would have to be the case, or else you could not distinguish between the entire array and an element of the array... which becomes paramount in the definition of the indexing operation. The language definition is quite precise that a pointer to an element of an array is nothing more than that; a pointer to one element of the array. Since this could easily be confused with the (real, although not yet discussed/introduced) idea of a pointer to an array then we have to stick with the language definition. Again, when we consider how indexing works - this will become a very important distinction. But, to movitate this, and "jump ahead" a little, this declaration int (*ap)[5]; is a pointer to an array of 5 `int' elements. Those are the terms reserved by the language definition. "ap" is actually is a separate object (a separate "box") that points to 5 other `int' objects, thus "ap" is a pointer to an array of 5 `int' elements. That is very different from: int *ip; int array[5]; ip = array; In this situation, it is very clear that `ip' is a pointer to an `int', and that it happens to point to the first `int' alement of array (because of the rules we've already discussed), but that's as far as the language definition carries us. But, "ip" is a box that can contain the location of an `int' box. "ap" is a box that can contain the location of an array of 5 `int' boxes... so, "ap" and "ip" are quite different types, different "kinds" of boxes. And, as I mentioned before - that becomes very important when indexing is defined. So, while there may be other terms we could use, "pointer to an array" has already been taken by the language definition and is very well defined. I could see myself throwing around some of the other words that have been mentioned here (saying that, for example, a pointer points "into" an array.) But those are colloquialisms without any formal definition... so, they can mean just about whatever anyone would like them to mean at any time, which makes talking about them kinda difficult. Maybe we could coin some new terms??? I would be happy to discuss them, but I think they are outside the bounds of the C/C++ language definition. (That is not to say that in some other programming language, or other situation, they would not be appropriate - I just believe that is not the correct characterization for C/C++, and certainly not in the spirit of the language definitions.) - Dave Rivers - -- rivers@dignus.com Work: (919) 676-0847 Get your mainframe programming tools at http://www.dignus.com