Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #5107

Re: Problem with array objects

Newsgroups comp.lang.c++
From "A. Bolmarcich" <aggedor@earl-grey.cloud9.net>
Subject Re: Problem with array objects
References <slrniso5lm.s9.aggedor@earl-grey.cloud9.net> <fl6zp.117$Wy2.90@newsfe23.ams2> <slrnistau0.1od6.aggedor@earl-grey.cloud9.net> <9PDzp.2011$Am5.1296@newsfe05.ams2>
Message-ID <slrnit5drc.1qpu.aggedor@earl-grey.cloud9.net> (permalink)
Date 2011-05-17 12:59 -0500

Show all headers | View raw


On 2011-05-14, Paul <pchristor@yahoo.co.uk> wrote:
>
> "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> wrote in message 
> news:slrnistau0.1od6.aggedor@earl-grey.cloud9.net...
>> On 2011-05-13, Paul <pchristor@yahoo.co.uk> wrote:
>>>
>>> "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> wrote in message
>>> news:slrniso5lm.s9.aggedor@earl-grey.cloud9.net...
>>
>> [snip]
>>
>>> What is accessed when you dereference pparr once?
>>
>> The array named arr (the value &arr has been assigned to pparr).
>
> These are two different things.
> Dereferencing pparr gives you arr, that is an array-type object , not &arr.

The result of dereferencing pparr once being arr is what I have
been stating.  The result of the expression pparr is &arr (the
value to which pparr has been initialized).  The results of
dereferencing pparr is arr.

>>> Are you incapable of using a compiler to find this out?
>>
>> No, I'm capable.  Here is an example program.
>>
>>  #include <iostream>
>>  #include <typeinfo>
>>  int main() {
>>    int arr[4], (*pparr)[4]=&arr;
>>
>>    std::cout<<"typeid(arr)"<<
>>          ((typeid(arr)==typeid(*pparr))?"==":"!=")<<
>>          "typeid(*pparr)"<<std::endl;
>>    std::cout<<"&arr"<<((&arr==&(*pparr))?"==":"!=")<<
>>          "&(*pparr)"<<std::endl;
>>  }
>>
>> The output I get is
>>
>>  typeid(arr)==typeid(*pparr)
>>  &arr==&(*pparr)
>>
>> the results of the expressions arr and *pparr have the same type
>> and the same address; the results are the same object: the array
>> named arr.
> Typeid gives a string representation of an object TYPE, not an object.
> Its not the array of integer objects, its another object. It's an array-TYPE 
> object which decays into a pointer.
> Dereferencing pparr does not access the array of integer objects, it 
> accesses another object which decays into a pointer.

The result of typeid(arr), is a std::type_info object representing
the type of arr.  The fact that

  typeid(arr)==typeid(*pparr)

indicates that arr and *pparr have the same type.

The return value of the name() member function of class
std::type_info is a C-string whose implementation defined value
represents the name of the type.  With the GNU C++ compiler that I
use, the result of both typeid(arr).name() and typeid(*pparr).name()
is "A4_i".  That is, both arr and *pparr are an array of 4 int.

In some contexts an array, such as the result of the expression
arr or *pparr, is implicltly converted to a pointer to the first
element of the array.  A result that is an array of integers
object "decays into" a pointer to the first integer of the array.

> The array-type object can only be reperesented in a limited amount of ways :
> 1) typeinfo  represents it as a string in the form of "int[]"
> 2) sizeof represents this as an integer value.
> 3) Almost any other operation will cause it to be converted to a pointer, 
> and its value will be an address.

In this case, the array-type object is the array named arr.  As I
wrote just above, the value of typeid(arr).name() with the C++
compiler that I use is "A4_i", which denotes an array of 4 int.
The value of sizeof(arr) is 16, with the C++ compiler that I use
the sizeof(int) is 4, making the size of an array of 4 int 16.  In
some contexts array-to-pointer conversion is implicitly applied to
an array and the result of that conversion is a pointer to the
first element of the array.

> An array-type object is not a figment of my imagination it exists in C++. 
> Why do you refuse to accept that there is such an entity as an array-type 
> object?

I don't accept that there is an array-type object different from the
array because, as far as I can tell, there is nothing the C++
standard about there being such an array-type object different from
the array.  If you think there is something in the C++ standard
about it, please cite the specific paragraphs about an "array-type
object" different from an array.

In addition, I have posted the assembler file generated by a C++
compiler for an example program.  That assembler file does not
contain an "array-type object" different from the array.  That
example program and assembler output are also later in this post.

>>> You speak utter nonsense, and I am considering ignoring further posts 
>>> from
>>> you because of your unreasonableness.
>>
>> I'm not unreasonable.  I have answered your questions, both here and
>> in other posts.  I have also responed to questionable statements that
>> you have made and have given reasons that support my claims.
>>
> You are being unreasonable because you cannot accept that dereferencing 
> pparr doesn''t actually access the array but it gives access to an 
> array-type object.

I am being reasonable; I have given the reasons why dereferencing
pparr accesses an array in the same sense as using the identifier of
the array.  In this case, the array-type object that results from
dereferencing pparr is the array named arr.

> All that code you posted above is uneccessary bullshit to try an show things 
> how you want them to appear.

What I have shown is consistent with what is in the C++ standard
and the behavior of C++ compilers that I have used.  You are the
one who is trying to show things how you want them to appear, such
as there being an array-type object distinct from the array.

Apparently, you are drawing too close of a parallel between the
expression

  **pparr

with the declarations

  int arr[4], (*pparr)[4] = &arr;

and the expression

  **ppi

with the declarations

  int i, *pi = &i, **ppi = &pi;

In the latter case there are three objects: i, pi, and ppi.  Between
ppi and i there is an object (named pi) that stores a pointer to int.

In the former case there are two objects: arr and pparr.  Between
pparr and the int that is the first element of arr there is no
third object that stores a pointer to an int.

> simply coding :
>
> std::cout<< *pparr;
>
> is enough to prove that dereferencing pparr doesnt access the array, it 
> accesses and object which decays into a pointer.

What happens in this case is an implicit array-to-pointer conversion
from the array result of *pparr to a pointer to the first element of
the array.  In other words: dereferencing pparr accesses the array
and the array decays into a pointer to the first element of the array.

The result of the array-to-pointer conversion is used as the argument
in a call to the <<(const void*) member function of the ostream named
cout.

> I have stated numerous times that it is an array-TYPE object. So why dont 
> you understand when you do :
>
> std::cout<< typeid(*pparr).name();
>
> An array-TYPE is displayed. It's a TYPE not an OBJECT that is displayed by 
> typeid. The object that arr is, is an array-type object, which decays into a 
> pointer to the actuall array of integer objects.

That's right, typeid(*pparr).name() is a C-string that represents
the name of an array type, "A4_i" with the GNU C++ compiler that I
use.  It is the type of the result of the expression *pparr.  The
result of the expression *pparr is an array of 4 int.  That array is
subject to array-to-pointer conversion, and the result of that
conversion is a pointer to the first element of the array.  The
result that conversion is not a pointer to the array.

>> [snip]
>>
>>>> The fact that dereferencing pparr twice and arr once both result in
>>>> the first element of the array is consistent
>>> Its consistent with fuck all you arsehole.
>>> THere is fuck all that is consistent about dereferencing pparr twice and 
>>> arr
>>> once, except that it proves they are different levels of indirection. 
>>> WHich
>>> is what I have been telling you all along.
>>
>> I have never claimed that they have the same level of indirection.
>> Apparently you stopped reading what I wrote at the word "consistent"
>> and did not read what I actually wrote what dereferencing pparr twice
>> and arr once both resulting in the first element of the array is
>> consistent with.
>
> But we are not arguing about what dereferencing ppar twice and arr once is.
> We are aguing about the fact that dereferencing pparr ONCE points a 
> array-type object which stores an address, and it does not access the array 
> of integer objects.

Because pparr is a pointer to an array, the result of dereferencing
pparr is an array, just as the result of dereferencing a pointer to
an int is an int.  The array that results by dereferencing pparr is
the array named arr, not a different object which stores an address.

An example program I gave in a previous post was

  int arr[4] = {1,2,3,4};
  int (*pparr)[4] = &arr;

  int foo() {
    return **pparr;
  }

The assembler output for the function named foo using the GNU C++
compiler for an Intel 686 is

  LFB2:
          pushl   %ebp
  LCFI0:
          movl    %esp, %ebp
  LCFI1:
          movl    _pparr, %eax
          movl    (%eax), %eax
          popl    %ebp
          ret

The instruction

          movl    _pparr, %eax

copies the value stored in the C++ object named pparr into a register,
and the next instruction

          movl    (%eax), %eax

copies the value stored at that address into the register that holds
the return value of the function.  The expression **pparr accesses
only one C++ object that stores a memory address: the one named pparr.

> You claimed that there is no intermediate object and there is only one array 
> object, but you are incorrect. There is an array-type object and an array of 
> integer objects which are not stored in the same memory location They are 
> different entities or objects or whatever you want to call them, they are 
> different fucking things altogether.

You stated that there is an intermediate object.  I have been using
the word object with the meaning it has in C++.  You are the one who
called it an object, I am simply using what the word object means in
C++.

I supported my claim of there being only one array-type object in this
this case with the above example program and assembler file generated
by the GNU C++ compiler.  I did not include the data section of the
assembler file in the previous post.  The data section is

.globl _arr
        .data
        .align 4
_arr:
        .long   1
        .long   2
        .long   3
        .long   4
.globl _pparr
        .align 4
_pparr:
        .long   _arr

There are only two objects: one for an array of 4 int named arr in
the C++ program (initialized with the 4 values in C++ program) and
one for pointer to array of 4 int named pparr in the C++ program
(initialized with the address of the C++ object named arr).

There is only one array-type object here, the one named arr in the
C++ program.  In addition, there is no array-type object created
by the instructions generated for the expression **pparr (the
generated instructions are in this post about 60 lines ago).

I have provided reasons that support my claim; you claim that
there is an intermediate object without supporting reasons.

>>> Dereferencing pparr once accesses what?
>>
>> The array named arr (the value &arr has been assigned to pparr).
>>
> Ok so what is this object that 'arr' represents , do you accept that it is 
> an array-type object( which decays into a pointer) or do you still think 
> it's the array of integer objects?

The identifier arr represents an object of type array of 4 int.  That
object contains 4 subobjects of type int.  As with all objects of
type array, it some contexts array-to-pointer conversion is
implicitly applied to it and the result is a pointer to the first
element of the array.

>>> You dont seem to know.
>>
>> What I have stated is that dereferencing pparr once accesses the
>> array named arr in the same sense as using the identifier arr.
>
> It doesn't access THE array, It is dereferencing a pointer to an array-type 
> object. It accesses an array-type object which when accessed decays into 
> another pointer.

The result of dereferencing a pointer to an array is an array, just
as the result of dereferencing a pointer to int is an int.  In this
case, the object of type array that is the result of dereferencing
pparr is the array named arr; the result is not any other object.
As with all objects of type array, it some contexts array-to-pointer
conversion is implicitly applied to it and the result of the
conversion is a pointer to the first element of the array.

> Ok with the following code:
> int arr[3] = {1,2,3};
> int (*pparr)[3] = &arr;
> std::cout<<*pparr;
>
> If dereferencing pparr once accessed the array then it would output 1.
> It doesn't because it doesn't access the array, it accesses an array-TYPE 
> object, which decays into another pointer.

Deferencing pparr once access the array; accessing an array is not
the same as accessing the first element of the array.  An array and
its first element have different types.  The array result of *pparr
undergoes implicit array-to-pointer conversion and the output is what
the member function <<(const void*) of the ostream named cout outputs.

>>>> The array accessed by dereferencing pparr once and arr not at all
>>>> is implicitly converted to a pointer to the first element of the
>>>> array.  Dereferencing that pointer accesses the first element of
>>>> the array.
>>>
>>> NO ARRAY IS ACCESED WHEN DEREFERENCING PPARR ONCE !
>>
>> Here is what I wrote that you silently snipped.
>>
> It doesn't matter what you wrote if you're disagreeing, with what I wrote in 
> caps, you are wrong.

If it doesn't matter what I wrote if I disagree, I don't understand
why you write so much about what doesn't matter.  Because pparr is a
pointer to an array, the result of dereferencing it is an array.

>>  pparr is a level of indirection from arr.  Dereferencing pparr
>>  accesses an array in the same sense as using arr accesses an array,
>>  just as given the declaration
>>
>>    int i, *pi = &i;
>>
>>  dereferencing pi accesses an int in the same sense that using i
>>  accesses an int.
>
> pi needs to be dereferenced twice to access the array, i needs to be , and 
> can only be, dereferenced once.

There is no array involved with the above declaration of pi.
Dereferencing pi twice does not make sense.  The result of
dereferencing pi once is an int.  Dereferencing an int does not
make sense.

> It is completely incorrect to suggest that, when dereferencing, they access 
> the array in the same way.

I have given reasons and examples to support my claim, here all you
do is make a claim without any supporting reasons or examples.
Please give an example where dereferencing pparr does not access the
array named arr in the sense that using the identifier arr does.

>>> Are you stupid as well as incapable of using a compiler.
>>
>> I am neither.  I have supported my claims with quotes from the C++
>> standard, sample C++ programs, and assembler source generated by
>> a C++ compiler.  What I have not done is call someone stupid or
>> an arsehole, as you have done.
>>
>>> If you think I am wasting my time arguing with an idiot like you you can 
>>> go
>>> fuck yourself. Accept the facts arsehole, I've had enough of your
>>> unreasonable idiocy.
>>
>> I accept facts, such as what is actually in the C++ standard and the
>> output of C++ programs.  I have used those as reasons that support
>> what I have claimed.
>
> You don't accept the facts. You continue to claim that dereferencing pparr 
> accesses the array of integer objects and refuse to accept that it actually 
> accesses another object which is an array-type object that decays into a 
> pointer.. 

What I wrote was: "Dereferencing pparr accesses an array in the same
sense that using the name arr accesses an array."  I originally wrote
that in a followup to a post by you in which you wrote: "Dereferencing
pparr does not access the array it accesses a temporary pointer.  The
pointer pparr does not reference the array, it references an
array-type object."  See
http://groups.google.com/group/comp.lang.c++/msg/d921556db52ce388?hl=en

The result of dereferencing pparr is the array named arr, not
another object.  In some contexts that array result is implicitly
converted to a pointer to the first element of the array.

I have supported my claim with what is in the C++ standard about
the unary * operator and with the code generated by a C++ compiler
for a sample program.  You have not similarly supported your claim
that dereferencing pparr accesses an array-type object other than
the array named arr.

I accept facts, such as what is actually in the C++ standard and
the output of a C++ compiler.  I accept claims supported with facts.
No one should accept unsupported claims.

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-05-05 14:13 -0500
  Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-05 22:21 +0100
    Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-05-06 10:49 +1200
      Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-06 12:29 +0100
    Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-05-07 11:34 -0500
      Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-08 04:05 +0100
        Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-05-10 12:31 -0500
          Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-10 22:10 +0100
            Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-05-12 12:19 -0500
              Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-13 09:54 +0100
                Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-05-14 11:20 -0500
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-14 23:59 +0100
                Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-05-17 12:59 -0500
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-18 19:36 +0100
                Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-05-19 13:20 -0500
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-20 14:29 +0100
                Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-05-23 13:53 -0500
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-23 22:53 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-23 23:04 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-23 23:19 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-24 02:26 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-24 13:16 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-24 14:58 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-24 15:05 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-24 17:39 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-24 17:58 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-24 21:04 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-24 21:11 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-25 00:12 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-25 00:33 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-25 11:39 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-25 12:04 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-25 12:56 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-25 13:15 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-25 16:36 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-25 16:47 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-25 17:15 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-25 17:39 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-25 21:09 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-25 22:24 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 01:28 +0100
                Re: Problem with array objects Thomas David Rivers <rivers@dignus.com> - 2011-05-25 09:57 -0400
                Re: Problem with array objects "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-05-25 16:50 +0200
                Re: Problem with array objects Thomas David Rivers <rivers@dignus.com> - 2011-05-25 12:01 -0400
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-25 16:59 +0100
                Re: Problem with array objects Thomas David Rivers <rivers@dignus.com> - 2011-05-25 12:56 -0400
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-25 21:46 +0100
                Re: Problem with array objects Thomas David Rivers <rivers@dignus.com> - 2011-05-25 20:02 -0400
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 01:37 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-05-25 08:15 +1200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-24 22:23 +0100
                Re: Problem with array objects Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-24 17:01 -0700
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-25 11:48 +0100
                Re: Problem with array objects gwowen <gwowen@gmail.com> - 2011-05-25 04:06 -0700
                Re: Problem with array objects Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-25 13:50 -0700
                Re: Problem with array objects "io_x" <a@b.c.invalid> - 2011-05-25 19:03 +0200
                Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-05-25 12:44 -0500
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-25 21:04 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-25 22:20 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 11:00 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-26 12:07 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-05-26 09:32 +1200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 11:10 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-05-26 23:07 +1200
          Re: Problem with array objects Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-10 15:56 -0700
            Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-05-11 12:25 +1200
              Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-11 10:56 +0100
              Re: Problem with array objects Joshua Maurice <joshuamaurice@gmail.com> - 2011-05-11 14:09 -0700
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-12 13:31 +0100

csiph-web