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


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

Re: Problem with array objects

Newsgroups comp.lang.c++
From "A. Bolmarcich" <aggedor@earl-grey.cloud9.net>
Subject Re: Problem with array objects
References (1 earlier) <fl6zp.117$Wy2.90@newsfe23.ams2> <slrnistau0.1od6.aggedor@earl-grey.cloud9.net> <9PDzp.2011$Am5.1296@newsfe05.ams2> <slrnit5drc.1qpu.aggedor@earl-grey.cloud9.net> <llUAp.895$Tw4.494@newsfe26.ams2>
Message-ID <slrnitans0.14gr.aggedor@earl-grey.cloud9.net> (permalink)
Date 2011-05-19 13:20 -0500

Show all headers | View raw


On 2011-05-18, Paul <pchristor@yahoo.co.uk> wrote:
>
> "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> wrote in message 
> news:slrnit5drc.1qpu.aggedor@earl-grey.cloud9.net...
>> On 2011-05-14, Paul <pchristor@yahoo.co.uk> wrote:
>>>>
>>>>> 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.
>
> No you are confused. &arr is an operation being carried out on arr. pparr is 
> a pointer.
> Dereferencing pparr gives access to an array-type object(arr).
> This object decays into a pointer , in most situations.

I'm not confused.  pparr is a pointer to an array; pparr has been
initialized to &arr; the result of dereferencing pparr is arr.  This
is just like given the declaration

  int i, *pi = &i;

pi is a pointer to an int; pi has been initialized to &i; the result
dereferencing pi is i.

>>>>> 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.
>
> This is not telling us what pparr points to , it points to an object, not a 
> type, and that object is not a type_info object.

According to the C++ standard when typeid is applied to an expression,
the result refers to a type_info object representing the type of the
expression.  The output line

  typeid(arr)==typeid(*pparr)

of the above program indicates that arr and *pparr have the same type.
The output line

  &arr==&(*pparr)

of the above program indicates that pparr points to the object named
arr.

>> 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.
>
> You are confused what does typeinfo have to do with anything?

What typeid has to do with it is that I posted the above program that
compares the typeid and address of arr and *pparr because you wrote:

  Are you incapable of using a compiler to find this out?

That was in a reply to what I wrote:

  The results 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.

I posted a program that showed that arr and *pparr have the same
type and the same address.  Because they have the same type and
same address, the result of dereferencing pparr is arr.  I posted
the program to support a claim I made that you questioned.  You
asked a question, I gave a detailed answer.

>>> 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.
>>
> The value of sizeof(arr) has nothing to do with the values stored in the 
> array.

I never claimed it did.  The value of sizeof(arr) is the number of
bytes in the object named arr.

>>> 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.
> I dont need any standard to confirm what is comon sense. Dereferencing pparr 
> does not access the array of integer objects, it accesses an array-TYPE 
> object which is converted to a pointer in most cases.

Because we are discussing C++, what matters is what is in the C++
standard.  The C++ standard specifies requirements for
implementations of the C++ programming language.  If what is in
the C++ standard is different than someone's common sense, what
is correct for an implementation of C++ is what is in the standard.

The result of dereferencing a pointer to an array is an array.  The
type of that result is an array type.  As with all array results, in
some contexts array-to-pointer conversion is applied, and the result
of that conversion is a pointer to the first element of the 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.
>>
> What does asm have to do with anything?

To someone who understands it, it shows that the example C++
program does not contain an array-type object different from the
array.  I posted the example program to support my claim that
there is not an array-type object different from the array.

>>>>> 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.
> But it doesn't access the array. You cannot access the array of integer 
> objects by dereferencing pparr once, you MUST dereference it twice.

Dereferencing pparr twice accesses the first element of the array.
Accessing an element of an array is not the same as accessing the
array, because an element of an array and the array have different
types.

>>> 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.
>
> You have shown nothing but refusal to acknowledge the fact that 
> dereferencing pparr doesn't access the array.

What I have shown supports my claim: "Dereferencing pparr accesses
an array in the same sense that using the name arr accesses an
array."  If you want to claim that they don't both access the
array in the same sense, please support your claim, for example by
citing paragraph(s) in the C++ standard or with a C++ program.

>> Apparently, you are drawing too close of a parallel between the
>> expression
>>
>>  **pparr
>
> Apparently this has nothing to do with my understanding of the word 
> "parallel".
> Perhaps you have your own meaning for this word.

A standard meaning of the word parallel is: "a person or thing that
is similar or analogous to another" (from
http://oxforddictionaries.com/view/entry/m_en_gb0604160#m_en_gb0604160).
**pparr is similar to **ppi (in the continuation of what I wrote,
below); they both have ** followed by an identifier.

>> 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.
> There are no objects here there is just your text and it shows only you 
> cannot accept that dereferencing pparr does not acces the array.

According to the C++ standard: an object is created by a definition.
The statement

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

is a definition of three objects, while the statement

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

is a definition of two objects.

>> 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.
>>
> Blah blah, you are incorrect.

On my, a claim about me being incorrect without any supporting
reasons.  That is a difference between us, I support my claims, such
as with above example of the difference between **pparr and **ppi.

[snip]

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 Thomas David Rivers <rivers@dignus.com> - 2011-05-26 09:08 -0400
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 15:19 +0100
                Re: Problem with array objects Thomas David Rivers <rivers@dignus.com> - 2011-05-26 14:45 -0400
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 21:02 +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 "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 13:09 +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 "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 13:22 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-26 14:14 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 15:27 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-26 15:52 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 16:45 +0100
                Re: Problem with array objects Leigh Johnston <leigh@i42.co.uk> - 2011-05-26 17:04 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 17:41 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-05-27 07:44 +1200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 21:10 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-05-27 09:05 +1200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-27 00:15 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-05-27 11:32 +1200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-27 01:39 +0100
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-27 01:56 +0100
                Re: Problem with array objects Ian Collins <ian-news@hotmail.com> - 2011-05-27 13:18 +1200
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-27 11:06 +0100
                Re: Problem with array objects "A. Bolmarcich" <aggedor@earl-grey.cloud9.net> - 2011-05-26 14:38 -0500
                Re: Problem with array objects "Paul" <pchristor@yahoo.co.uk> - 2011-05-26 21:15 +0100
          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