P
Paul
Leigh Johnston said:On 16/06/2011 20:06, Paul wrote:
int* p1 = new int;
int* p2 = new int[22];
int* p3=0;
p1 points to a single integer, p2 points to an array of integers
and p3
points to nothing at all.
p2 points to the first element of an array of integers; crucially
what
do we say p2 points to if we do:
++p2;
Continuing to say that p2 points to an array when it doesn't point
to
the first element of an array is confusing at best.
No p2 points to an array of integer objects.
I've told you before you can point to a banana in a bunch yet you
also
point to the bunch of bananas at the same time.
You have told all of us your crazy analogies before; crazy analogies
that remain crazy no matter how many times you repeat them or vary
them.
Pointing to a banana is not the same as pointing to a bunch of
bananas.
'p2' is a pointer to a single 'int' not an array of 'int's.
According to the draft standard (and I think it is not likely to
change) p2 is a "pointer to /an/ array" though not a "pointer to
array". Likewise, ++p2 is also a "pointer to /an/ array" that so
happens to also be a sub-array.
So, unless the standard changes, your opinion directly conflicts
with it; you are wrong and Paul is consistent with the standard.
And according to the draft C standard the term "pointer to an array"
is what the draft C++ standard refers to as a "pointer to array". I am
of the opinion that the draft C++ standard is in error changing the
meaning of "pointer to an array": try applying some common sense.
int *p = 0; // pointer to int, pointer to an int
No , this pointer points to nothing. It can be said it is of "type
pointer to int", which is often shortened to "pointer to int".
The context of this is not the same a what is pointed-to, this context
is referring to the pointers type, or what the pointer is.
int (*pa) = 0; // pointer to array, pointer to an array
Again this pointer points to nothing.
You are confusing the term "is a pointer to ..whatever", with the
context of what is pointed-to and what type the pointer is.
You are the one confusing what type of pointer a pointer is and the
dynamic type of any object that is pointed to. In the case of arrays a
pointer to an element (sub-object) of an array object is not a pointer to
an array; there is a similar situation for class types:
base* pb = 0;
'pb' is a pointer to a base even if the dynamic type of the object pointed
to is derived from base.
You need to stop confusing runtime concepts with compile time concepts.
A pointer points-to whatever it points to, whether it be runtime or compile
time.
A pointers type is a different thing from what it points-to.
In your example pb points to nothing , it is a null pointer and it does not
point to any object whether you are thinknig about compile or runtime.
Its type is "pointer to base", this does not mean it points to a base.
Again you are confusing runtime with compile time.
No it points-to nothing in compile time and runtime.
Yes compile time and runtime are different contexts and if it is not
obvious which context is meant then the context should be made explicit.
What you are saying is gibberish as it is not clear what you mean by
"pointer to the array" as you like to confuse compile time and runtime
contexts/concepts in an almost arbitrary fashion to try and suit your
argument at a particular moment in time.
No its clear that a pointer to an array is a pointer that...drumroll
...points to an array.
No its not the most sensible, it is one of two different views.int* p = some_opaque_function(); // 'p' is a pointer to an int
int (*p)[42] = some_opaque_function(); // 'p' is a pointer to an array of
int
As you can see the default position of assuming a compile time context
(static type) is the most sensible position.
Pre-compiled code wouldn't be very sensible if there was no runtime in which
to run the program.
This is where you are wrong, your view is that one context is correct and
the other is not , but they are both correct.