Am 23.04.2011 02:52, schrieb Paul:
Why would it even cross your mind that that is a lie?
Because I know that you know what it prints. You don't need to actually
run it.
Replying to yourself ^^^^^^
Yeah yeah an array is not a pointer.
I reapeat that for every misconception of yours that is ultimately due
to your failure to understand that an array is not a pointer.
Where is this object stored? USB stick? CDRom?
Nowhere. That's my point. It's an rvalue, not an lvalue. It is not
stored in memory, more specifically: it's not stored in the memory the
array occupies, and there's also no intermediate "identifier object"
that stores this pointer value.
No you said :
"A pointer-type object stores memory addresses as their value. There is no
memory address contained in the bytes of the object we reached.
What's in there are the values of the actual array elements"
So what type are you talking about that stores values of array elements?
You already acknowledged that the pointer values of
arr
&arr
&arr[0]
are all the same.
That means there cannot be any memory address stored at *&arr.
No its not, by definition its an array-type object and it's non modifiable.
See below on "object of array type" vs. "array-type object".
An array is a contiguous sequence of objects of element-type, and it is
modifiable.
I'll quote you on that.
A pointer to an array-type is a pointer to a non modifiable array-type
object.
A pointer to an array of objects is a pointer to a modifiable array of
objects.
You do not acknoweldge these different pointer types, which seems to suggest
you are either ignorant or you lack knowledge about the C++ language.
This is all due to your non-standard use of the term "array".
You are making an off-by-one error concerning level of indirection.
C++ standard | Paul
--------------------------+-----------------------------
sequence of elements | array
array | array-type object
pointer to array | pointer to array-type object
pointer to element | pointer to array
Of course. And when you dereference a pointer to an array, you access the
array.
Yes like so:
int* p = new int[64];
That's not a pointer to an array....
*p = 1; /*Accessing the array*/
Accessing an element of the array...
p[5] = 6; /*Another way to derefernece the pointer*/
Yes. When you dereference a pointer to an array, you get the array itself.
All of it at once. The whole array. That thing that contains 10 integers.
No, you cannot access a whole array at once, unless its size one or some
other silly example.
As I said. You cannot directly access an array, you can only access its
elements. But the level of indirection is the same as the array when you
dereference a pointer to the array.
Yes I can, a char* can point to a single char or an array of chars. You are
the one who cannot understand this.
Ok then. What you fail to understand is how an array can be a single
object in its own right.
But a struct is a singular object that has subobjects. And that is
exactly the same with an array. That's why a struct is a valid analogy.
And with :
int arr[10] ={0};
int (*p)[10] =&arr;
/*dereferencing this accesses an object that holds the address of arr.
*/
No. That would mean there is a memory address stored in the memory
location that p points to. This is false.
Examine the object you get when you dereference it an you will see that
it's
a memory address.
An array is not a pointer.
So you've been saying.
I reapeat that for every misconception of yours that is ultimately due
to your failure to understand that an array is not a pointer.
/*dereference it twice to access the array of integer objects*/
/*This is an indirect pointer to the array of integers*/
int a[3];
int *x = a;
int (*y)[3] =&a;
std::cout<< static_cast<void*>(x)<< std::endl
<< static_cast<void*>(y)<< std::endl;
The only difference is the type. Whereas with:
int* x;
int** y =&x;
the actual pointer values differ.
The difference is in levels of indirection, as I explained above.
Your two pointers x& y do not have the same level of indirection ,
regradless of their value.
Which pair of x&y? (I should have named them differently)
Both actually
You cannot dereference 'y' to access three integer objects,
Theoretically
dereferencing 'y' would access three integer objects, but it doesn't.
Not only in theory, but actually in practice, it does (the first y).
It does not access any integer object, because it is not type int*. You
cannot assign anything to it , because it does not access the integer
objects.
Same with an array object. This only means that you get the array when you
dereference a pointer to an array.
No an array object is not the same, you can dereference an array object to
access the array.
You can dereference (*y) again to access the array elements, just like
you can with the array "a" itself.
int arr[10];
'arr' is what I would consider an array type identifier object. My
That "identifier object" thing again. You think this is some kind of
intermediate strawman or something? It's the array itself. An object
that
contains 10 subobjects. An object that lives in memory, has an address
and
a size, where the size is the sum of all subobjects' sizes.
No an array-type object is not an object that contains sub-objects.
This is what you are unable to see. But that's how it is.
8.3.4 Arrays:
"An object of array type contains a contiguously
allocated non-empty set of N subobjects of type T."
No thats describing a object of array type , not an array-type object.
Are you seriously arguing that "object of array type" is not the same as
"array-type object"?
You are really hopeless.
But wait, I already knew that.
An array-type object is the following 'arr' object:
int arr[500];
arr is an object. That object has a type. That type is an array type.
Therefore arr is an object of array type. Therefore it is an array.
Therefore it has elements. Those elements are subobjects.
Therefore arr is an object of array type that contains a contiguously
allocated non-empty set of 500 subobjects of type int.
There is no use arguing when you refuse to acknowledge the most basic
things.
An object of array type, is a region of storage such as an array of integer
objects.
This is not an exception to the rule.
int a[3];
int (*p)[3] =&a;
a[1] = 1;
(*p)[1] = 1;
You dereference this pointer twice.
Yes...
You have obviously tried to hide this
fact behind the subscript syntax.
No, because I do the same with "a". After dereferencing p by writing
(*p),
I'm at a level of indirection that is the same as "a" itself. I
demonstrate this by applying the same subscript to both, accessing the
same element of the array.
So why did you present it as an example that only dereferenced it once?
Because the point was that the first dereference yields something
equivalent to the array itself. The subscriptions only serve to show that
the levels of indirection are the same.
What exactly is something equivalent to the array itself?
It's equivalent because you can substitute "(*p)" anywhere you can use "a".
But to you, "a" is not the array itself.
I don't deny the fact that 'a' is an array.
But more accurately 'a' is an array-type.
'a' is not an array in the same context , that it's a sequence of objects.
You contradict yourself.
Either you claim that an "array-type object" is not an array, and stand
by that POV, or you acknowledge that "a" *is* an array.
If you change position every time it suits you, you can't be taken
seriously.
But wait, I already knew you do that.
I reapeat that for every misconception of yours that is ultimately due
to your failure to understand that an array is not a pointer.
More accurately 'a' is an array-type identifier.
Nonsese it is you who have the narrow minded view here , not I.
It must be, or else your refusal to acknowledge that "a" is an array
does not make sense.
If you say that "a is an array" is false, and you also say that "only
the sequence in memory is an array" is also false, then
to you, *what* exactly *is* an array??
No wonder it's no good communicating with you, if the word "array" rings
different bells at different times in your head, and no one can predict,
which. Are you doing that on purpose?
Yes because you cannot access an array as a whole. You can only reference
it. Yes.
And the only way to reference it is with a pointer to one if its elements,
usually the first element.
You can of course reference an array with a pointer to the array. It's
simple.
Yes you can only access its elements , because that is what an array is, a
sequence of elements.
So therefore a pointer to an array is a pointer to its elements.
By value, yes. By type, no.
Which shows that in this situation the array-type object is simply treated
as a pointer.
The automatic conversion kicks in at about every opportunity, because
without it, there's not much you can do with the array.
But that does not mean the array object stores a pointer value.
its an identifier of array-type , but its not an object?
An identifier is a label. An object can have a label. An object is not
equivalent to its label.
The label says "This object is named 'arr'. Its type is 'int[3]'".
So if we take the address of this identifier, what are we taking the address
of:
The address of an identifier , or the address of an object.?
You can't take the address of an identifier. It's only syntax. If you
write "&arr", you take the address of the object named "arr", because
you have to somehow refer to the object. That's what names are for.
The standard says "is":
"the type of the identifier of D is an array type"
The standard says:
The type is a type.
The type is an array type.
The type of the identifier is an array type.
The type of the identifier of D is an array type.
It does not say:
The identifier is an array type.
Dude, that's basic english. That's not even got anything to do with C++.
If you can't read, then there's no point in arguing with you.
But wait, I already knew this.
But there is a level of reference there. An array identifier needs to be
dereferenced to access an array.
That's because it has subobjects. You have to somehow express which of
the subobjects you want to access.
With a struct, where the subobjects have names, you can just use the "."
operator and refer to the subobject via its name.
With an array, all subobjects are anonymous, sou you have to use pointer
arithmetics to address them.
An array object and a struct object are at the same level of
indirection. A pointer to a struct and a pointer to an array object are
at the same level of indirection. A pointer to an element of the array
is at a different level of indirection.
Peter