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: Sat, 28 May 2011 20:38:17 -0400 Organization: Aioe.org NNTP Server Lines: 174 Message-ID: <4DE19579.1060300@dignus.com> References: <5cadnQfIzuppjUHQnZ2dnUVZ8kidnZ2d@giganews.com> <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> 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++:5789 Paul wrote: > > "Thomas David Rivers" wrote in message > news:4DE10DA2.9050201@dignus.com... > >> >> >> To return to that, do you agree that in this declaration: >> >> int arr[5]; >> >> 'arr' is the name of the contigous set of 5 `int' elements? >> >> And, to go to the next step, would you agree that in this >> declaration: >> >> int i; >> >> `i' is the name of single `int'? >> > Yes I agree, you may continue. So - we should then consider something fairly important... what does "name" mean? I would ask that we consider the 'name' of something to be the designation of the location that contains that 'something'. And, I want to movitave that definition with the following scenario. If we can imagine that variables, in the C/C++ sense, are simply "boxes" that contain their values - like shoeboxes on a shelf, then the "name" associated with the variable is simply the name associated with a "box." Let's imagine that this shelf can contain many boxes, and that the boxes are numbered... box #0, box #1, box #2.. A box can be referred to by its number - its location on the shelf, or if we associate a name with a box #; we can use the name. For example, box #51 might have the name `i' associated with it. Thus, if we consider this snippet of C code: int i; i = 5; the semantics of that would be something similar to: define a box name 'i', allocate space for it, let's say that is box #51, associate location #51 with the name 'i'. produce the manifest `int' constant 5 Find the box with the name 'i', oh - it's box #51. store the manifest constant 5 into box #51. Similarly, the snippet: int i,j; i = j; might be realized in this way: define a box named 'i' that can contain int-typed objects, say, box #51. define a box named 'j' that can contain int-typed objects, say, box #52. Given the name 'j'; find its box - oh - it's box #52. Retrieve (fetch) the value from box #52. Given the name 'i'; find its box - oh - it's box #51. Store the value previously fetched value into box #51. So far, I've only talked about boxes that can contain `int'-typed values. Let's introduce a new box, and say that it can contain the location (the box #) of another box, and the other box can contain `int'-typed values. We would call this new box a "pointer" to an `int'-typed box, because it doesn't contain the `int'-type value itself, but instead tells us the location (the box #) of the value. Now - let's consider this: int *ip; int i; ip = &i; in this mindset - what does this mean? To discuss this, we need to define the &-operator. Le's say that the &-operator is named 'address of' and that it returns the location (the box #) of its operand. Say, for example, if `i' happened to be box #51, then the expression "&i" would produce location #51. Remember - I can have two kinds of boxes on my shelf, boxes that contain `int'-typed values, and boxes that contain the location of other `int'-typed boxes. So, &i doesn't produce an `int'-typed value, it produces a location. In this example, it produced #51. (I have been careful to use '#' to indicate location numbers instead of simple `int'-typed values.. this distinction will become important.) So - the semantics of that statement would be (if I may be so bold as to be a little loose on the details): define a box named 'ip' - it can contain the location of other `int'-typed boxes, let's say it is box #52. define a box named 'i' - it can contain `int' values, let's say it's box #51. Apply the &-operator to the box named `i' - oh - i is box #51, so &i produces the location #51. Look up the name `ip - oh - that's box #52. Store our previously found location (#51) into box #52. OK - now - let's say that I happen to buy my boxes from a manufacturer that can only make 2-kinds of boxes, those boxes that can contain `int' elements, and those boxes that can contain the location of other boxes that contain `int' elements. (that is, `int' boxes and `int *' boxes). So, let's look at this: int *ip; int arr[5]; What can this do? I propose it does the following: define a box named 'ip', that box is allowed to contain the location of other `int'-type boxes; let's say that is box #52. define a space of 5 boxes, each of these boxes is on the shelf starting at, say, location #53. Each of these boxes is an `int'-typed box. The boxes are contiguous, starting a location #53 and going thru location #57 (inclusive.) Since `arr' (at the C/C++ level) is a single object, the location associated with `arr' is #53 (the start of the 5 contiguous boxes on the shelf.) That is, in this scenario, the location of 'ip' is box #52, the location of 'arr' is box #53. `ip' uses one box, `arr' uses 5 boxes. With this, we can provide a definition of "name".... the "name" of the variable provides a mechanism for finding precisely which "box" (the box #, or location of the box) houses the value of the variable. The "name" is nothing more than a convenience for mapping the location of the variable. So - in our example, the name 'ip' is asociated with box #52, the name 'arr' is associated with box #53. Before I go on, I want to check to see if you agree with everything so far... - Dave Rivers - -- rivers@dignus.com Work: (919) 676-0847 Get your mainframe programming tools at http://www.dignus.com