Problem with array objects

D

Drew Lawson

Do you really expect someone who don't know whether the C++ language has
one or more standards to grasp such a clear and simple bit of logic?

What I've seen (mostly quotes the last month or so) suggests that
Paul lacks even the slightest understanding of noun/verb number
agreement, and likely any understanding of apostrophes.

Years ago, I inherited part of a project from a coworker who was
leaving, to my relief. The phrasing I had at that time was, "couldn't
program his way out of a wet paper bag." I don't know what Paul's
*code* looks like, but his reasoning reminds me of that situation.

Alas, the clueless rarely resign from Usenet.
 
P

Paul

Well, no. (Actually I was being facetious - this point has been made
hundreds of times before, and that's just by those people whos posts I
read. My point, which I concede to be unclear, as sarcasm and
facetiousness so often are on Usenet, was that since Paul was not
swayed by this argument the first 100 times, making it again was a
waste of perfectly good electrons)


What has been argued 100 times before is that an char* can point to an array
of chars.
Your argument against this is incorrect , whether you say it has been said
100 times of 20trillions times makes no difference, its wrong.

Why do you persisit in being wrong? Why not just accept the truth and be
done with it?
LOL you guys are so comical its unbelievable. You would argue that the sky
wasn't blue, in fact someone on this forum actually made a serious attempt
to do this. Others have attempted to argue that there is only one C++
standard, I mean c'mon guys get real and accept when you are wrong, and move
on.
 
I

Ian Collins

What has been argued 100 times before is that an char* can point to an array
of chars.

That should be "a char*". A char* can point to an array of cabbages,
but that does not make a char* a cabbage.
Others have attempted to argue that there is only one C++
standard,

There is only one language standard. Care to cite a reference to
pointer types in another?
 
P

Paul

Drew Lawson said:
What I've seen (mostly quotes the last month or so) suggests that
Paul lacks even the slightest understanding of noun/verb number
agreement, and likely any understanding of apostrophes.

Years ago, I inherited part of a project from a coworker who was
leaving, to my relief. The phrasing I had at that time was, "couldn't
program his way out of a wet paper bag." I don't know what Paul's
*code* looks like, but his reasoning reminds me of that situation.

Sounds to me like you used his code anyway, because you probably didn't know
what to do yourself.
Since you prove yourself unable to understand the difference between a
pointer-type and what a pointer points to if I was ever in the unfortunate
position to inherit your code I would probably just bin it and rewrite it
from scratch
 
P

Paul

Ian Collins said:
That should be "a char*". A char* can point to an array of cabbages, but
that does not make a char* a cabbage.

No but it makes it a pointer to an array of cabbages.

There is only one language standard. Care to cite a reference to pointer
types in another?
No there is more than one standard relevant to the C++ langauge.
 
P

Paul

A. Bolmarcich said:
What is in the C++ standard about pointers to arrays is not relevant
to
the
statement

int *p = new int[4]

because there are no pointers to arrays in the statement, only
pointers
to
int. A relevant part of the C++ standards for that statement is
paragraph
1 of section 5.3.4 (New) that I quoted (see above).

p is a pointer to an array of 4 ints, not only to one single int.

No, p is a pointer to an int. If it were a pointer to an array of
4 ints, then the byte address that the result of the expression

p+1

points to would be the byte address that p points plus
4*sizeof(int). However, the byte address of what that expression
points to is the byte address that p points to plus sizeof(int).

Do you understand the difference between a pointer-type and what a
pointer
points to?

What you call pointer-type determines what a C++ pointer points
to. Here is paragraph 1 of section 5.3 of the C++ standard:

The unary * operator performs indirection: the expression to
which it is applied shall be a pointer to an object type, or
a pointer to a function type and the result is an lvalue
referring to the object or function to which the expression
points. If the type of the expression is pointer to T, the
type of the result is T. [Note: a pointer to an incomplete
type (other than cv void ) can be dereferenced. The lvalue thus
obtained can be used in limited ways (to initialize a reference,
for example); this lvalue must not be converted to an rvalue,
see 4.1. ]

I accept exactly what is in the C++ standard. Given the declaration

int *p = new int[4];

p is a pointer to an int and the result of *p is an int. What you
wrote, "p is a pointer to an array of 4 ints", is incorrect; the
result of *p is not an array of 4 ints..
No p is a pointer to an array of 4 ints.
When it is dereferenced it returns an int because the pointer-type is int*,
which complies with this quotation from the standards on dereferencing.

You cannot get a pointer that, when dereferenced, returns 4 ints. Or 40 ints
or whatever size the array is.
The fact that the result of incrementing p is a pointer to the next
int address indicates that p is a pointer to an int, not a pointer
to an array of 4 ints.
No this is incorrect a pointer of type int* can point to both a single int
and an array of ints.
In the declaration

int a2i[3][4], (*p1i)[4] = a2i;

p1i is a pointer to an array of 4 ints.

But when its dereferenced in doesn't return 4 ints. It is not a pointer to
an array(entity) of 4 ints, it is a pointer to array-type.

When an array is converted to a pointer it is converted to a pointer-type of
an (n-1) dimensionsal array.
Incrementing it results in
a pointer to the next array of 4 ints. The subscript operator can
be applied to the result of dereferencing p1i, as the subscript
operator can be applied to any array in C++.

The result of the initialization expression a2i is given in
paragraph 7 of section 8.3.4 of the C++ standard:

A consistent rule is followed for multidimensional arrays. If E
is an n-dimensional array of rank ixjx...xk, then E appearing in
an expression is converted to a pointer to an (n - 1)-dimensional
array with rank jx...xk. If the * operator, either explicitly or
implicitly as a result of subscripting, is applied to this pointer,
the result is the pointed to (n - 1)-dimensional array, which
itself is immediately converted into a pointer.
The above clearly expalins how arrays are converted to pointers in C++.
A 1dim array such as int arr[16], is converted to a pointer type int*.
A 2dim array such as int arr[3][16] is converted to a pointer type int
(*)[16].
I accept exactly what is in the standard. The 2-dimensional array
a2i in the initialization expression is converted to a pointer to a
1-dimensional array. As a result of the initialzation, p1i, a
pointer to a 1-dimensional array, points to that 1-dimensional array.
If a 2d array is converted to a pointer , the pointer points to a 2d array.
The pointed to TYPE is a 1d array and you are obviously confusing this with
with the pointed to entity.

[snip]
So according to you this is incorrect:

"The pointer declaration char *p, on the other hand, requests a place
which
holds a pointer, to be known by the name ``p''. This pointer can point
almost anywhere: to any char, or to any contiguous array of chars, or
nowhere "

Im sorry but I agree with the above quotation , and if you disagree then
I
diasagree with you and I think it is more likely that you are incorrect
than
the source of this quotation.

I don't disagree that a char* can point almost anywhere. However,
no matter where it points, an operation on a char* treats what the
char* points to as a char.

But you disagree that char* can point to an array? According to you *char
returns only one char and not multiple chars therefore it is incorrect to
say a char* can point to an array of chars. So you must disagree with the
above.

You must also disagree with the following:
<quote ref=http://www2.research.att.com/~bs/glossary.html>
"char* - pointer to a char or an array of char."
</quote>

Now since you are in complete disagreement with highly respected authorities
who were probably teaching C++ before you'd even heard of it. Do you not
think that perhaps you're missing something important here?




char* p= new char[16];
p[3] = '3';
The above treats the char pointer as an array, not as a single char.
 
P

Paul

A. Bolmarcich said:
[snip]
What you call pointer-type determines what a C++ pointer points
to. Here is paragraph 1 of section 5.3 of the C++ standard:

The unary * operator performs indirection: the expression to
which it is applied shall be a pointer to an object type, or
a pointer to a function type and the result is an lvalue
referring to the object or function to which the expression
points. If the type of the expression is pointer to T, the
type of the result is T. [Note: a pointer to an incomplete
type (other than cv void ) can be dereferenced. The lvalue thus
obtained can be used in limited ways (to initialize a reference,
for example); this lvalue must not be converted to an rvalue,
see 4.1. ]

I accept exactly what is in the C++ standard. Given the declaration

int *p = new int[4];

p is a pointer to an int and the result of *p is an int. What you
wrote, "p is a pointer to an array of 4 ints", is incorrect; the
result of *p is not an array of 4 ints..
No p is a pointer to an array of 4 ints.
When it is dereferenced it returns an int because the pointer-type is
int*,
which complies with this quotation from the standards on dereferencing.

The fact that derefencing it returns an int indicates that it is a
pointer to int. Derefencing a pointer to an array of 4 ints would
return an array of 4 ints.
You cannot get a pointer that, when dereferenced, returns 4 ints. Or 40
ints
or whatever size the array is.

A pointer to an array of 4 ints, when dereferenced, returns an array
of 4 ints. Look at the output of running the following program.

#include <iostream>
#include <typeinfo>

int main() {
int a1i[4], (*pa1i)[4] = &a1i;

std::cout<<"typeid( a1i)="<<typeid(a1i).name()<<std::endl;
std::cout<<"typeid(*pa1i)="<<typeid(*pa1i).name()<<std::endl;
}
You are dereferencing an array-type , not an array.
For example:

int arr[40] ={0};
int* parr = arr;
int (*pparr)[40] = &arr;

std::cout<< "address of arr[0]:\t" << &arr[0] <<std::endl;
std::cout<< "value of *parr:\t\t" << *parr <<std::endl;
std::cout<< "value of *pparr\t\t" << *pparr <<std::endl;

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.


The (implementation defined) values returned by typeid(a1i).name()
and typeid(*pa1i).name() are the same. The output indicates that
both ai1 and *pai1 are arrays of 4 ints.
No it outputs the type, not the pointed to object.
*pa1i does not derefernece a pointer to the array, it dereferenes a pointer
to a tempory object of array-type.
Basically its a fancy pointer to a pointer.
[snip]
No this is incorrect a pointer of type int* can point to both a single
int
and an array of ints.

If an int* could point to an array of int, the following statement
that tries to initialize an int* with a pointer to an array of int
would be allowed, but it isn't.

int a1i[4], *pi = &a1i;
&ali is a pointer derivation from an array-type.
This creates a pointer that references an array-type, not the actual array
of ints.
To reference an array of ints, you need to use a pointer-type int*, and you
do not use the addressof& operator, like so:
int* p = a1i;
This pointer , when dereferenced, accesses the array like so:
p[int_offset];

The following pointer-type
int (*p)[4] =&a1i;
Does not access the array when dereferenced, it accesses an array-type
object. This object is bascially another pointer to the array.
Pointing to an array-type object, is not the same as pointing to the array
of ints. It points to AN array , yes an array-type object( which is
basically another pointer under the hood), it doesn't point to THE array of
ints.
In the declaration

int a2i[3][4], (*p1i)[4] = a2i;

p1i is a pointer to an array of 4 ints.

But when its dereferenced in doesn't return 4 ints. It is not a pointer
to
an array(entity) of 4 ints, it is a pointer to array-type.

What derefencing p1i retuns is an array of 4 ints. You omitted the
word "array" from what I wrote.

When you dereference p1i, you create a temporary array-type object the value
of which is another memory address. You do not get an array of 4 ints,
example:

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

std::cout<< *p;

The type of p is an array-type, this means it points to an object of
array-type, not an array of int objects.

That's right for multidimensional arrays. For example, when the
conversion is done on a 2d array the result is a pointer to a 1d
array.
Its the same for 1d arrays, its just a bit silly to say a (1-1)dimension
array, which is a single object.
Incrementing it results in
a pointer to the next array of 4 ints. The subscript operator can
be applied to the result of dereferencing p1i, as the subscript
operator can be applied to any array in C++.

The result of the initialization expression a2i is given in
paragraph 7 of section 8.3.4 of the C++ standard:

A consistent rule is followed for multidimensional arrays. If E
is an n-dimensional array of rank ixjx...xk, then E appearing in
an expression is converted to a pointer to an (n - 1)-dimensional
array with rank jx...xk. If the * operator, either explicitly or
implicitly as a result of subscripting, is applied to this pointer,
the result is the pointed to (n - 1)-dimensional array, which
itself is immediately converted into a pointer.
The above clearly expalins how arrays are converted to pointers in C++.
A 1dim array such as int arr[16], is converted to a pointer type int*.
A 2dim array such as int arr[3][16] is converted to a pointer type int
(*)[16].
I accept exactly what is in the standard. The 2-dimensional array
a2i in the initialization expression is converted to a pointer to a
1-dimensional array. As a result of the initialzation, p1i, a
pointer to a 1-dimensional array, points to that 1-dimensional array.
If a 2d array is converted to a pointer , the pointer points to a 2d
array.
The pointed to TYPE is a 1d array and you are obviously confusing this
with
with the pointed to entity.

According to the C++ standard an n-dimensional array is converted to
a pointer to an (n - 1)-dimensional array. The result of that
conversion on a 2d array is a pointer to 1d array. A pointer to a
1d array points to a 1d array, not to a 2d array. You appear to be
confusing C++ with a programming language in which arrays are
polymorphic over dimensions.
You are confusing the whole context of the statement in the standard.
It doesn't mean the array is converted to a pointer that no longer points to
the array.


Run out of time need to cut this short.
BBFN
..
 
P

Paul

A. Bolmarcich said:
A pointer to an array of 4 ints, when dereferenced, returns an array
of 4 ints. Look at the output of running the following program.

#include <iostream>
#include <typeinfo>

int main() {
int a1i[4], (*pa1i)[4] = &a1i;

std::cout<<"typeid( a1i)="<<typeid(a1i).name()<<std::endl;
std::cout<<"typeid(*pa1i)="<<typeid(*pa1i).name()<<std::endl;
}
You are dereferencing an array-type , not an array.
For example:

int arr[40] ={0};
int* parr = arr;
int (*pparr)[40] = &arr;

std::cout<< "address of arr[0]:\t" << &arr[0] <<std::endl;
std::cout<< "value of *parr:\t\t" << *parr <<std::endl;
std::cout<< "value of *pparr\t\t" << *pparr <<std::endl;

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.

Dereferencing pparr accesses an array in the same sense that using
the name arr accesses an array.
No it doesn't
*arr =1; /*Accesses the array*/
*pparr=1; /*Cannot do this*/
In the above statement, *pparr dereferences a pointer to an array,
resulting in an array to which array-to-pointer conversion is applied,
resulting in a pointer to the first element of the array.

The expression &arr[0] also results in a pointer to the first element
of the array. Due to value to which pparr was initialized, the output
to cout of the expressions *pparr and &arr[0] are the same. The
output to cout of the expression arr would also be the same, due to an
implicit array-to-pointer conversion.

The expression *parr dereferences a pointer to int, resulting in the
pointed to int. That same int would be output by the statement

std::cout<< "value of (*pparr)[0]\t\t" << (*pparr)[0] <<std::endl;

or

std::cout<< "value of arr[0]\t\t" << arr[0] <<std::endl;

Look at the difference in the output of the two statements:

std::cout<< "value of pparr\t" << pparr <<std::endl;
std::cout<< "value of pparr+1\t" << pparr+1 <<std::endl;

On a system where sizeof int is 4 the difference will be 0xa0
(decimal 160). That is the amount of space occupied by an
array of 40 ints. pparr is a pointer to an array of 40 ints.

The variable parr is a pointer to an int, not a pointer to an array.
The variable pparr is a pointer to an array, not a pointer to a
pointer to an array.
No it outputs the type, not the pointed to object.
*pa1i does not derefernece a pointer to the array, it dereferenes a
pointer
to a tempory object of array-type.
Basically its a fancy pointer to a pointer.

I never said that typeid outputs the pointed to object. The
declaration was

int a1i[4], (*pa1i)[4] = &a1i;

pa1i is a pointer to an array. *pa1i dereferences it resulting in
an array. The only objects here are an array (named a1i) and a
pointer to array (named pa1i). There is no pointer to a temporary
object here.
No there are four integer objects here, that you fail to acknowledge.

[snip]

The fact that the result of incrementing p is a pointer to the next
int address indicates that p is a pointer to an int, not a pointer
to an array of 4 ints.
No this is incorrect a pointer of type int* can point to both a single
int
and an array of ints.

If an int* could point to an array of int, the following statement
that tries to initialize an int* with a pointer to an array of int
would be allowed, but it isn't.

int a1i[4], *pi = &a1i;

Correction: the line

int a1i[4], *pi = &a1i;

should have been

int a1i[4], *(pa1i)[4] = &a1i;
&ali is a pointer derivation from an array-type.
This creates a pointer that references an array-type, not the actual
array
of ints.
To reference an array of ints, you need to use a pointer-type int*, and
you
do not use the addressof& operator, like so:
int* p = a1i;
This pointer , when dereferenced, accesses the array like so:
p[int_offset];

The expression &a1i is a pointer to the array named a1i (just as the
expression &i where i is an int is a pointer to the int named i).
Dereferencing &a1i results in the array of int named a1i.

The expression p[int_offset], where p is a pointer to an int, treats
p as if it is a pointer to an element of an array of ints. The
result of the subscript operation is the int that is int_offset
elements away from the array element pointed to by p.
The following pointer-type
int (*p)[4] =&a1i;
Does not access the array when dereferenced, it accesses an array-type
object. This object is bascially another pointer to the array.
Pointing to an array-type object, is not the same as pointing to the
array
of ints. It points to AN array , yes an array-type object( which is
basically another pointer under the hood), it doesn't point to THE array
of
ints.

Here, the object named p is a pointer to the array named a1i.
Dereferencing it results that array. The expression
No it doesn't , dererencing this pointer results in a non modifiable object
that cannot be used to access the array unless converted.
So it results in something that can be converted to a pointer to the array.
(*p)[int_offset]

access the int_offset element of that array.

Look at the output of the following program.

#include <iostream>
#include <typeinfo>
int main() {
int a1i[4], (*pa1i)[4]=&a1i;

std::cout<<"typeid(a1i)"<<((typeid(a1i)==typeid(*pa1i))?"==":"!=")<<
"typeid(*pa1i)"<<std::endl;
std::cout<<"a1i"<<((a1i==*pa1i)?"==":"!=")<<"*pa1i"<<std::endl;
}

a1i and *pa1i have the same type and value. pa1i points to the
array of int named a1i.
In the declaration

int a2i[3][4], (*p1i)[4] = a2i;

p1i is a pointer to an array of 4 ints.

But when its dereferenced in doesn't return 4 ints. It is not a pointer
to
an array(entity) of 4 ints, it is a pointer to array-type.

What derefencing p1i retuns is an array of 4 ints. You omitted the
word "array" from what I wrote.

When you dereference p1i, you create a temporary array-type object the
value
of which is another memory address. You do not get an array of 4 ints,
example:

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

std::cout<< *p;

The type of p is an array-type, this means it points to an object of
array-type, not an array of int objects.

There is no temporary array-type object the value of which is
another memory address. There are two objects: an array named arr
and a pointer to array named p. Due to the initialization, p points
the array of int named arr.

Again you fail to acknoweldge the four integer objects.
Where is this object that you describe as "the array named arr" strored?

Evaluating the expression *p results in an array, the one named
arr; array-to-pointer conversion is applied to that array resulting
in a pointer to the first element of the array, a pointer to int.
That pointer to int is converted to a pointer to void to call the
operator<<(const void*) of cout.

[snip]
You are confusing the whole context of the statement in the standard.
It doesn't mean the array is converted to a pointer that no longer points
to
the array.

I'm not confusing anything. I accept what the C++ standard states.
Here, it states that a conversion is done from an array to a pointer
to an element of the array. What is pointed to is an element of the
array, not the array.

You must be pointing to the array , to point to an element. Where is this
element stored if not witihin the array?
 
I

Ian Collins

A. Bolmarcich said:
news:[email protected]... [snip]
A pointer to an array of 4 ints, when dereferenced, returns an array
of 4 ints. Look at the output of running the following program.

#include<iostream>
#include<typeinfo>

int main() {
int a1i[4], (*pa1i)[4] =&a1i;

std::cout<<"typeid( a1i)="<<typeid(a1i).name()<<std::endl;
std::cout<<"typeid(*pa1i)="<<typeid(*pa1i).name()<<std::endl;
}

You are dereferencing an array-type , not an array.
For example:

int arr[40] ={0};
int* parr = arr;
int (*pparr)[40] =&arr;

std::cout<< "address of arr[0]:\t"<< &arr[0]<<std::endl;
std::cout<< "value of *parr:\t\t"<< *parr<<std::endl;
std::cout<< "value of *pparr\t\t"<< *pparr<<std::endl;

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.

Dereferencing pparr accesses an array in the same sense that using
the name arr accesses an array.
No it doesn't

All together now - oh yes it does!

try adding

(*pparr)[0] = 42;
std::cout<< "value of arr[0]\t\t" << arr[0] <<std::endl;
arr[10] = 1234;
std::cout<< "value of (*pparr)[0]\t\t" << (*pparr)[10] <<std::endl;
 
P

Paul

Ian Collins said:
A pointer to an array of 4 ints, when dereferenced, returns an array
of 4 ints. Look at the output of running the following program.

#include<iostream>
#include<typeinfo>

int main() {
int a1i[4], (*pa1i)[4] =&a1i;

std::cout<<"typeid( a1i)="<<typeid(a1i).name()<<std::endl;
std::cout<<"typeid(*pa1i)="<<typeid(*pa1i).name()<<std::endl;
}

You are dereferencing an array-type , not an array.
For example:

int arr[40] ={0};
int* parr = arr;
int (*pparr)[40] =&arr;

std::cout<< "address of arr[0]:\t"<< &arr[0]<<std::endl;
std::cout<< "value of *parr:\t\t"<< *parr<<std::endl;
std::cout<< "value of *pparr\t\t"<< *pparr<<std::endl;

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.

Dereferencing pparr accesses an array in the same sense that using
the name arr accesses an array.
No it doesn't
What I wrote was:
No it doesn't
*arr =1; /*Accesses the array*/
*pparr=1; /*Cannot do this*/

There is no need to snip something so short. Obviously you are attempting to
change the context of my post from that of a reasonable debate into a blunt
non explanatory argument.

All together now - oh yes it does!
You seem to have nothing positive to add as an individual. All you attempt
to do is create a "more is better" argument.
try adding

(*pparr)[0] = 42;
std::cout<< "value of arr[0]\t\t" << arr[0] <<std::endl;
arr[10] = 1234;
std::cout<< "value of (*pparr)[0]\t\t" << (*pparr)[10] <<std::endl;
This code only confirms that *arr, is not the same as *pparr, in any sense.
Which is exactly what I said.


As I said dereferencing pparr doesn't access the arrray it accesses an
array-type object.
As can be shown:
std::cout<< *p;
std::cout<< typeid(*p).name();
*p = 50; /*Wrong. cannot access the array*/

There are two ways this array-type object can be used to access the array
(i) Convert to a pointer.
(ii) Convert to a reference.

For example:
(i) int* p = *p;
(ii) int (&r)[40] = *p;

These are the only two object-types that can access the array, namely:
(i) A pointer to an array.
(ii) A reference to an array.
 
I

Ian Collins

Ian Collins said:
A pointer to an array of 4 ints, when dereferenced, returns an array
of 4 ints. Look at the output of running the following program.

#include<iostream>
#include<typeinfo>

int main() {
int a1i[4], (*pa1i)[4] =&a1i;

std::cout<<"typeid( a1i)="<<typeid(a1i).name()<<std::endl;
std::cout<<"typeid(*pa1i)="<<typeid(*pa1i).name()<<std::endl;
}

You are dereferencing an array-type , not an array.
For example:

int arr[40] ={0};
int* parr = arr;
int (*pparr)[40] =&arr;

std::cout<< "address of arr[0]:\t"<< &arr[0]<<std::endl;
std::cout<< "value of *parr:\t\t"<< *parr<<std::endl;
std::cout<< "value of *pparr\t\t"<< *pparr<<std::endl;

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.

Dereferencing pparr accesses an array in the same sense that using
the name arr accesses an array.
No it doesn't
What I wrote was:
No it doesn't
*arr =1; /*Accesses the array*/
*pparr=1; /*Cannot do this*/

There is no need to snip something so short. Obviously you are attempting to
change the context of my post from that of a reasonable debate into a blunt
non explanatory argument.

I was replying to text above, not the example, which had no relevance to
the text.

Saying "*pparr=1; /*Cannot do this*/" is no different form writing

struct X { int n; };

X x;
X* px = &x;
*px = 1;
try adding

(*pparr)[0] = 42;
std::cout<< "value of arr[0]\t\t"<< arr[0]<<std::endl;
arr[10] = 1234;
std::cout<< "value of (*pparr)[0]\t\t"<< (*pparr)[10]<<std::endl;
This code only confirms that *arr, is not the same as *pparr, in any sense.
Which is exactly what I said.

Did anyone dispute that? Remember you disputed "Dereferencing pparr
accesses an array in the same sense that using the name arr accesses an
array".

So how does "(*pparr)[0] = 42;" differ from "arr[0] = 42;"?

Does (*pparr) not dereference pparr?
As I said dereferencing pparr doesn't access the arrray it accesses an
array-type object.
As can be shown:
std::cout<< *p;
std::cout<< typeid(*p).name();

Try adding

std::cout << (typeid(arr) == typeid(*pparr)) << std::endl;
*p = 50; /*Wrong. cannot access the array*/

Obviously (assuming p above is pparr). You have exactly the same
situation as the struct example above. But if you dereference the
pointer, you can use the result as if it were the original array, as my
additions and running the above showed you.
There are two ways this array-type object can be used to access the array
(i) Convert to a pointer.
(ii) Convert to a reference.

I think the examples above disprove that.
 
P

Paul

Ian Collins said:
A pointer to an array of 4 ints, when dereferenced, returns an array
of 4 ints. Look at the output of running the following program.

#include<iostream>
#include<typeinfo>

int main() {
int a1i[4], (*pa1i)[4] =&a1i;

std::cout<<"typeid( a1i)="<<typeid(a1i).name()<<std::endl;
std::cout<<"typeid(*pa1i)="<<typeid(*pa1i).name()<<std::endl;
}

You are dereferencing an array-type , not an array.
For example:

int arr[40] ={0};
int* parr = arr;
int (*pparr)[40] =&arr;

std::cout<< "address of arr[0]:\t"<< &arr[0]<<std::endl;
std::cout<< "value of *parr:\t\t"<< *parr<<std::endl;
std::cout<< "value of *pparr\t\t"<< *pparr<<std::endl;

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.

Dereferencing pparr accesses an array in the same sense that using
the name arr accesses an array.

No it doesn't
What I wrote was:
No it doesn't
*arr =1; /*Accesses the array*/
*pparr=1; /*Cannot do this*/

There is no need to snip something so short. Obviously you are attempting
to
change the context of my post from that of a reasonable debate into a
blunt
non explanatory argument.

I was replying to text above, not the example, which had no relevance to
the text.

Saying "*pparr=1; /*Cannot do this*/" is no different form writing

struct X { int n; };

X x;
X* px = &x;
*px = 1;
Saying "*pparr=1; /*Cannot do this*/". is completely different from writing
the above code.
pparr's type is not a pointer to an X. It's type is pointer to array of
ints.
try adding

(*pparr)[0] = 42;
std::cout<< "value of arr[0]\t\t"<< arr[0]<<std::endl;
arr[10] = 1234;
std::cout<< "value of (*pparr)[0]\t\t"<< (*pparr)[10]<<std::endl;
This code only confirms that *arr, is not the same as *pparr, in any
sense.
Which is exactly what I said.

Did anyone dispute that? Remember you disputed "Dereferencing pparr
accesses an array in the same sense that using the name arr accesses an
array".
dereferencing pparr does not access the array , it..*drumroll* dereferences
pparr.
So how does "(*pparr)[0] = 42;" differ from "arr[0] = 42;"?
If you can't see that they differ in levels of indirection, then you do not
understand the code.
Does (*pparr) not dereference pparr?


Try adding

std::cout << (typeid(arr) == typeid(*pparr)) << std::endl;

This is just a pointless comment that in no way suggests the *pparr access
the array.
This simply shows that *pparr has the same type as arr. I have already
stated that *pparr yields an array-type object.
Obviously (assuming p above is pparr). You have exactly the same
situation as the struct example above. But if you dereference the
pointer, you can use the result as if it were the original array, as my
additions and running the above showed you.
A struct is not an array. And yes obviously p is an example of a
pointer-type int(*)[N]
I think the examples above disprove that.
What examples? And what do you suggest they disprove about the above?
If you disagree with what I said here , can you show me how to access an
array without using a pointer or a reference, or converting to one?
If you cannot provide an example of code to back up your statement is
nothing more than meaningless drivel.
 
I

Ian Collins

Ian Collins said:
A pointer to an array of 4 ints, when dereferenced, returns an array
of 4 ints. Look at the output of running the following program.

#include<iostream>
#include<typeinfo>

int main() {
int a1i[4], (*pa1i)[4] =&a1i;

std::cout<<"typeid( a1i)="<<typeid(a1i).name()<<std::endl;
std::cout<<"typeid(*pa1i)="<<typeid(*pa1i).name()<<std::endl;
}

You are dereferencing an array-type , not an array.
For example:

int arr[40] ={0};
int* parr = arr;
int (*pparr)[40] =&arr;

std::cout<< "address of arr[0]:\t"<< &arr[0]<<std::endl;
std::cout<< "value of *parr:\t\t"<< *parr<<std::endl;
std::cout<< "value of *pparr\t\t"<< *pparr<<std::endl;

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.

Dereferencing pparr accesses an array in the same sense that using
the name arr accesses an array.

No it doesn't

What I wrote was:
No it doesn't
*arr =1; /*Accesses the array*/
*pparr=1; /*Cannot do this*/

There is no need to snip something so short. Obviously you are attempting
to
change the context of my post from that of a reasonable debate into a
blunt
non explanatory argument.

I was replying to text above, not the example, which had no relevance to
the text.

Saying "*pparr=1; /*Cannot do this*/" is no different form writing

struct X { int n; };

X x;
X* px =&x;
*px = 1;
Saying "*pparr=1; /*Cannot do this*/". is completely different from writing
the above code.
pparr's type is not a pointer to an X. It's type is pointer to array of
ints.
Exactly.
try adding

(*pparr)[0] = 42;
std::cout<< "value of arr[0]\t\t"<< arr[0]<<std::endl;
arr[10] = 1234;
std::cout<< "value of (*pparr)[0]\t\t"<< (*pparr)[10]<<std::endl;

This code only confirms that *arr, is not the same as *pparr, in any
sense.
Which is exactly what I said.

Did anyone dispute that? Remember you disputed "Dereferencing pparr
accesses an array in the same sense that using the name arr accesses an
array".
dereferencing pparr does not access the array , it..*drumroll* dereferences
pparr.

Neither does arr. Remember the origin claim you disputed?
"Dereferencing pparr accesses an array in the same sense that using the
name arr accesses an array".
So how does "(*pparr)[0] = 42;" differ from "arr[0] = 42;"?
If you can't see that they differ in levels of indirection, then you do not
understand the code.

Quite. Remember the words "Dereferencing pparr'?
This is just a pointless comment that in no way suggests the *pparr access
the array.
This simply shows that *pparr has the same type as arr. I have already
stated that *pparr yields an array-type object.

So dereferencing pparr allows you to access the array in the same manner
as arr. You have just disproved your own claim.

Well done.
 
P

Paul

Ian Collins said:
Ian Collins said:
On 04/24/11 11:04 AM, Paul wrote:
A pointer to an array of 4 ints, when dereferenced, returns an
array
of 4 ints. Look at the output of running the following program.

#include<iostream>
#include<typeinfo>

int main() {
int a1i[4], (*pa1i)[4] =&a1i;

std::cout<<"typeid( a1i)="<<typeid(a1i).name()<<std::endl;

std::cout<<"typeid(*pa1i)="<<typeid(*pa1i).name()<<std::endl;
}

You are dereferencing an array-type , not an array.
For example:

int arr[40] ={0};
int* parr = arr;
int (*pparr)[40] =&arr;

std::cout<< "address of arr[0]:\t"<< &arr[0]<<std::endl;
std::cout<< "value of *parr:\t\t"<< *parr<<std::endl;
std::cout<< "value of *pparr\t\t"<< *pparr<<std::endl;

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.

Dereferencing pparr accesses an array in the same sense that using
the name arr accesses an array.

No it doesn't

What I wrote was:
No it doesn't
*arr =1; /*Accesses the array*/
*pparr=1; /*Cannot do this*/

There is no need to snip something so short. Obviously you are
attempting
to
change the context of my post from that of a reasonable debate into a
blunt
non explanatory argument.

I was replying to text above, not the example, which had no relevance to
the text.

Saying "*pparr=1; /*Cannot do this*/" is no different form writing

struct X { int n; };

X x;
X* px =&x;
*px = 1;
Saying "*pparr=1; /*Cannot do this*/". is completely different from
writing
the above code.
pparr's type is not a pointer to an X. It's type is pointer to array of
ints.

Exactly.

So *pparr=1; IS completely different from *px=1;
Which you originally tried to present at being no different.

Your are inconsistent.
try adding

(*pparr)[0] = 42;
std::cout<< "value of arr[0]\t\t"<< arr[0]<<std::endl;
arr[10] = 1234;
std::cout<< "value of (*pparr)[0]\t\t"<<
(*pparr)[10]<<std::endl;

This code only confirms that *arr, is not the same as *pparr, in any
sense.
Which is exactly what I said.

Did anyone dispute that? Remember you disputed "Dereferencing pparr
accesses an array in the same sense that using the name arr accesses an
array".
dereferencing pparr does not access the array , it..*drumroll*
dereferences
pparr.

Neither does arr. Remember the origin claim you disputed? "Dereferencing
pparr accesses an array in the same sense that using the name arr accesses
an array".

*arr =1;
Almost everything you say is completely incorrect, do you actually know
anything about C++ or are you just another noob trying to act as if you know
something?


And you snipped something from the previous post:
I think the examples above disprove that.
What examples? And what do you suggest they disprove about the above?
If you disagree with what I said here , can you show me how to access an
array without using a pointer or a reference, or converting to one?
If you cannot provide an example of code to back up your statement is
nothing more than meaningless drivel.
</quote>

I take it, from your silent snipping, that you unable to provide any code
that proves your claim.

And people wonder why I call them idiots.
<snip>
 
I

Ian Collins

Ian Collins said:
On 04/24/11 11:04 AM, Paul wrote:
A pointer to an array of 4 ints, when dereferenced, returns an
array
of 4 ints. Look at the output of running the following program.

#include<iostream>
#include<typeinfo>

int main() {
int a1i[4], (*pa1i)[4] =&a1i;

std::cout<<"typeid( a1i)="<<typeid(a1i).name()<<std::endl;

std::cout<<"typeid(*pa1i)="<<typeid(*pa1i).name()<<std::endl;
}

You are dereferencing an array-type , not an array.
For example:

int arr[40] ={0};
int* parr = arr;
int (*pparr)[40] =&arr;

std::cout<< "address of arr[0]:\t"<< &arr[0]<<std::endl;
std::cout<< "value of *parr:\t\t"<< *parr<<std::endl;
std::cout<< "value of *pparr\t\t"<< *pparr<<std::endl;

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.

Dereferencing pparr accesses an array in the same sense that using
the name arr accesses an array.

No it doesn't

What I wrote was:
No it doesn't
*arr =1; /*Accesses the array*/
*pparr=1; /*Cannot do this*/

There is no need to snip something so short. Obviously you are
attempting
to
change the context of my post from that of a reasonable debate into a
blunt
non explanatory argument.

I was replying to text above, not the example, which had no relevance to
the text.

Saying "*pparr=1; /*Cannot do this*/" is no different form writing

struct X { int n; };

X x;
X* px =&x;
*px = 1;

Saying "*pparr=1; /*Cannot do this*/". is completely different from
writing
the above code.
pparr's type is not a pointer to an X. It's type is pointer to array of
ints.

Exactly.

So *pparr=1; IS completely different from *px=1;
Which you originally tried to present at being no different.

No. I said "*px = 1;" is no different from "*pparr=1;". Both are errors.

What has that do do with "Dereferencing pparr accesses an array in the
same sense that using the name arr accesses an array"?
Almost everything you say is completely incorrect,

What exactly did I say that was in correct? I said you were wrong in
denying the quote above and you have consistently failed to address that.
And you snipped something from the previous post:

What examples?

(*pparr)[0] = 42;
And what do you suggest they disprove about the above?
If you disagree with what I said here , can you show me how to access an
array without using a pointer or a reference, or converting to one?
If you cannot provide an example of code to back up your statement is
nothing more than meaningless drivel.
</quote>

I take it, from your silent snipping, that you unable to provide any code
that proves your claim.

I've never tried noisy snipping. I have shown you that

(*pparr)[0] = 42;

is equivalent to

arr[0] = 42;

and

typeid(arr) == typeid(*pparr)

Thus "Dereferencing pparr accesses an array in the same sense that using
the name arr accesses an array", the point you denied.
 
P

Paul

Ian Collins said:
A pointer to an array of 4 ints, when dereferenced, returns an
array
of 4 ints. Look at the output of running the following program.

#include<iostream>
#include<typeinfo>

int main() {
int a1i[4], (*pa1i)[4] =&a1i;

std::cout<<"typeid(
a1i)="<<typeid(a1i).name()<<std::endl;

std::cout<<"typeid(*pa1i)="<<typeid(*pa1i).name()<<std::endl;
}

You are dereferencing an array-type , not an array.
For example:

int arr[40] ={0};
int* parr = arr;
int (*pparr)[40] =&arr;

std::cout<< "address of arr[0]:\t"<<
&arr[0]<<std::endl;
std::cout<< "value of *parr:\t\t"<<
*parr<<std::endl;
std::cout<< "value of *pparr\t\t"<<
*pparr<<std::endl;

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.

Dereferencing pparr accesses an array in the same sense that using
the name arr accesses an array.

No it doesn't

What I wrote was:
No it doesn't
*arr =1; /*Accesses the array*/
*pparr=1; /*Cannot do this*/

There is no need to snip something so short. Obviously you are
attempting
to
change the context of my post from that of a reasonable debate into
a
blunt
non explanatory argument.

I was replying to text above, not the example, which had no relevance
to
the text.

Saying "*pparr=1; /*Cannot do this*/" is no different form writing

struct X { int n; };

X x;
X* px =&x;
*px = 1;

Saying "*pparr=1; /*Cannot do this*/". is completely different from
writing
the above code.
pparr's type is not a pointer to an X. It's type is pointer to array of
ints.

Exactly.

So *pparr=1; IS completely different from *px=1;
Which you originally tried to present at being no different.

No. I said "*px = 1;" is no different from "*pparr=1;". Both are errors.

Altogether now! No you didn't say that.
What exactly did I say that was in correct? I said you were wrong in
denying the quote above and you have consistently failed to address that.
When I said dereferencing pparr does not access the array , you said
"neither does arr", which is obvioulsy wrong because dereferencing arr does
access the array.

Do I really have to point out the meaning an of every single statement
because you are too stupid to interpret anything correctly.

And you snipped something from the previous post:

What examples?

(*pparr)[0] = 42;
You Fail.
This code dereferences pparr then uses the subscript operator, which
converts (*pparr) to an int* which is then further dereferenced.

This clarifies what you claim to disprove cannot be disproved, at least not
by you anyway.
 
P

Peter Remmers

Am 24.04.2011 14:31, schrieb Paul:
When I said dereferencing pparr does not access the array , you said
"neither does arr", which is obvioulsy wrong because dereferencing arr does
access the array.

Do I really have to point out the meaning an of every single statement
because you are too stupid to interpret anything correctly.

If you weren't so superficial, and would actually *read* and
*understand* the statement you are trying to dispute, you would see that
it's you whose arguments completely miss the point.

It's not "*parr" vs. "*arr", but "*parr" vs. "arr".

Peter
 
P

Paul

Peter Remmers said:
Am 24.04.2011 14:31, schrieb Paul:

If you weren't so superficial, and would actually *read* and *understand*
the statement you are trying to dispute, you would see that it's you whose
arguments completely miss the point.

It's not "*parr" vs. "*arr", but "*parr" vs. "arr".
The statement in dispute is "dereferencing pparr does not access the array".
And it was you who originally disputed it.
You said dereferencing pparr accesses the array in the same way arr does,
which is incorrect as can be shown:
**pparr=1;
*arr=1;

Dereferencing ppparr accesses an array-type object, not the array of
integers. Dereferencing pparr TWICE accesses the array.
This is not the same as dereferencing arr ONCE to access the array.
 
I

Ian Collins

Altogether now! No you didn't say that.

You even quoted me saying it.
When I said dereferencing pparr does not access the array , you said
"neither does arr", which is obvioulsy wrong because dereferencing arr does
access the array.

(*pparr) and arr have the same type. So whatever applies to one,
applies to the other.
Do I really have to point out the meaning an of every single statement
because you are too stupid to interpret anything correctly.

Ah, resorting to insults again, good job.
(*pparr)[0] = 42;
You Fail.
This code dereferences pparr then uses the subscript operator,

Well that is how you access an array! How is it different from
arr[0] = 42?

I'll remind you again, the statement you disputed was:

"Dereferencing pparr accesses an array in the same sense that using the
name arr accesses an array".

Now given typeid(arr) == typeid(*pparr), how can that be false?
 
I

Ian Collins

The statement in dispute is "dereferencing pparr does not access the array".
And it was you who originally disputed it.
You said dereferencing pparr accesses the array in the same way arr does,
which is incorrect as can be shown:
**pparr=1;
*arr=1;

Goodness me, you really have excelled your self here, haven't you?

We all know *pparr is dereferencing pparr and

typeid(arr) == typeid(*pparr), so

*arr === **pparr.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top