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: Fri, 27 May 2011 15:07:07 -0400 Organization: Aioe.org NNTP Server Lines: 130 Message-ID: <4DDFF65B.8010007@dignus.com> References: <846dndOds94DPEbQnZ2dnUVZ8ridnZ2d@giganews.com> <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> 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++:5722 Paul wrote: > > "Thomas David Rivers" wrote in message > news:4DDFA87C.9060808@dignus.com... > >> Paul wrote: >> >>> >>> "Thomas David Rivers" wrote in message >>> news:4DDE9FCD.9050005@dignus.com... >>> >>>> Paul wrote: >>>> >>>>> >>>>>> >>>>>> So - do we agree that an array is a contigous set of like-typed >>>>>> elements, >>>>>> where the elements are accessed via the []-operator? >>>>>> >>>>> Yes I aggree with that. >>>>> >>>> >>>> So - next let's examine a rather simple declaration of an array in >>>> C/C++. >>>> >>>> int arr[5]; >>> >>> >>> >>> No do a dynamic array like so: >>> int* arr = new int[5]; >>> >>> Then there is no confusion about array objects, an array is simply >>> the region of memory storing the integer objects and nothing more. >>> >>> Having read ahead you seem to be slowly introducing this "arr" >>> object into the equation without first aggreeing on a definition of >>> what exactly "arr" is. And that is what was the original argument. >>> >>> In the above example of a dynamic array there is no confusion that >>> "arr" is a pointer. >>> >>> >> >> You are correct - what you have declared there is a pointer to an >> integer, >> (the `int *arr' portion), and that pointer is initialized with some >> dynamically >> allocated space (the `new' portion.) The dynamically allocated >> space is a >> contiguous set of 5 'int' elements (the `int[5]' portion.) The >> pointer's name is 'arr'. >> >> That's all well and good, but it is very different from what I was >> talking about. >> >> What I'd like to focus on is this simple declaration: >> >> int arr[5]; >> >> Can we agree that the declaration of >> >> int arr[5]; >> >> represents, at runtime, a set of 5 contiguous 'int' elements. The >> name of the set of 5 contiguous elements it 'arr'. The name 'arr' >> refers to the runtime location of the set of 5 contiguous elements. >> >> If we can, I'd like to restrict the conversation to just that for the >> moment... we can get to the other stuff soon enough... but, one >> thing at a time. >> > Yes I agree with this, but before we can proceed any further we need > to agree on what exactly "arr" is. > You are calling it a name that refers to the contiguous sequence of > elements here. > I would like to establish just what exactly it is because it seems to > store a memory address as can be show with: > int arr[5]; > int* p = arr; > > So lets try to agree about what exactly arr is. > As you know I have been calling it an array type object. > > That would basically be the next step... However, I want to hold to the definition; 'arr' is simply the name of the 5 contiquous int elements. Now - let's take up the problem of assignment to a pointer... Let's consider this snippet: int i; int *ip; ip = &i; would you agree that the semantics of that would be that 'i' is the name of an `int'. `ip' is the name of a pointer to an `int'. The expression: &i denotes "the address of the `int' named `i'" And the expression: ip = &i; denotes "compute the address of the `int' named 'i', store that value into the pointer-to-`int' named `ip'." Does that sound correct? If so, then we can begin to look at your example involving `arr'; and - we can compare the two with considerations toward just what it means to assign a value to the `int' pointer named `ip'. But - one thing at a time. - Dave Rivers - -- rivers@dignus.com Work: (919) 676-0847 Get your mainframe programming tools at http://www.dignus.com