Leigh Johnston said:
No, conclusion is fine. Nonsense are your attempts to equal "is"
and
"points to". And, they lead to poor coding and errors (see
your own
attempts earlier in this thread to explain your stance).
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Do you accept that the same pointer-type can point to an char
or an
array of
char's?
I accept that when pointer points to the first element of an
array, we
commonly say that it points to an array.
But in
int a[1];
int (*p)[1] = &a;
p is an actual, in C type system sense, pointer to an array. And
because of such things, one should take mental note when saying
"pointer to an array" for a pointer pointing to array's first
element.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Do you accpet that when Bjarne Stroustrup says a char* can point
to a
single char or an array of chars. He is in fact techincally
correct. And
he fully understand the C++ type system.
Do you not think its more likely that you are incorrect, if you
disagree
with him?
Stop appealing to authority. Bjarne is being informal but
obviously he
is correct as what he is saying does not disagree with what others
have been telling you; basically "type" in the following two
phrases
can refer to a *different* type:
1) "pointer to a type"
2) "the type of the object pointed to".
Your problem is your inability to differentiate the two phrases
above.
"pointer to" is different to "pointed to" or "points to" as
"pointer
to" partially describes the type of the pointer variable not
what is
being pointed to.
No its quite straight forward: Bjarne says that a char* pointer can
point to a single char or an array of chars, you say otherwise.
You obviously did not read my reply: "pointer to" is different to
"points to". Take the time to properly read the replies people
make or
**** off and stop posting to this newsgroup you time waster.
No pointer to and points to is more or less the same thing. Both
terms
refer to the pointed to object.
No they are not "more or less the same thing"; "more or less the same
thing" is woolly language and has no place in a technical discussion;
also see below.
You say that a char* does not point to an array and only points to
a
single char. You further your wrongness by saying that a type:
char (*)[3]
is a pointer to a 1d array, when this is actually a pointer to a 2d
array , because pointers to arrays are (n-1) dimensions of the
pointed
to array.
You are wrong again:
char a[3]; // 1d array
char(*p)[3] = &a; // pointer to a 1d array
No you are wrong because this doesn't mean that this type of pointer
cannot be used as a pointer to a 2d array like so:
char a[3][3];
char (*p)[3] =a;
No p is still a pointer to a 1d array; your code is invoking array
pointer decay as it is equivalent to:
char a[3][3];
char (*p)[3] =&a[0];
Your understanding of arrays and pointers is flawed.
Your understanding is flawed, the C++ standard defines a pointer to a
2d
array to be of this type/ level of indirection.
Your understanding is flawed:
char(*)[N] is a pointer to a 1d array
char(*)[N1][N2] is a pointer to a 2d array
No this is the pointer TYPE.
When a 1d array of chars is converted to a pointer the pointer-type is
char* , not char (*)[somesize].
Its all explained in the standards.
You take the address of a thus introducing an unneccessary extra
level
of indirection.
Of course; a pointer to an array is an extra level of indirection; a
pointer to an array element isn't.
No. According to the C++ standards, a pointer to an array is a
different
level of indirection, but in the opposite direction from what you are
saying.
That was just gibberish.
Now if Bjarne says one thing and you say it is incorrect, then
who is
more likely to be wrong?
Your appeal to authority is wrong on two counts:
1) An appeal to authority is a logical fallacy;
2) The authority you are appealing to actually does not agree with
your claim/argument (as I have described above).
The authority states that char* can point to a single char or an
array
of chars. Which is in direct agreement with me and disagrees with
you.
Again: there is a difference between "a pointer to" and "points to".
Consider:
struct base {};
struct derived : base {};
derived o;
base* p = &o;
p is a pointer to a base even though it points to an object of derived
type.
Its a pointer to what it points to , its the same thing.
No it isn't. A pointer has a type; a pointer's type does not have to
be the same type as the object it points to.
This is where you fail , because you have on many occassions said that a
pointer to T, can only point to a T.
No I haven't; I have said that a pointer to a scalar is not a pointer to
an array and have said that "pointer to" is different to "points to" if,
like you, we disregard technical accuracy.
You are the technically innacurate. If an object X points to an array then
it is a pointer to an array. Both terms involving the verb "point" where it
refers to the pointed-to object.
You are incorrectly trying to suggest that the term "is a pointer to" means
something different than the pointed to object.
If you mean its a pointer type pointer to X then say that because this is
the techincally accurate term. Not your twisted nonsense.
I have said that a pointer to a scalar is not a pointer to an array; a
pointer to a scalar can point to an array element of the same scalar type.
I am not inconsistent; you are both confused and cause confusion due to
your use of ambiguous terminology and lack of technical accuracy.
You are one who is inaccurate , the term "points to" and "is a pointer to"
both refer to the same pointed to object.
You attempt to use the term "is a pointer to" to mean is of type pointer to.
You are confused by the pointer-type and what it points to.
It is obvious to all that it is you who has been confused; is
currently confused and probably will continue to be confused as you
refuse to learn from others.
Additionally if the C++ standards defines something and you say its
incorrect, then who is more likely to be wrong?
Where have I have said that the C++ Standard is incorrect? I haven't
said any such thing so you are either lying or are confused.
You said that char (*p)[3] points to a 1d array and not to a 2d
array,
but the standard states different.
p is a pointer to a 1d array and the standard does not state
different; p may point to a 1d array subobject of a 2d array and if it
is pointing to the first 1d array subobject of the 2d array then one
can say it points to a 2d array but this is informal language and
technically inaccurate. As others have said "points into" is a more
acceptable term that covers all bases.
This is utter nonsesne the C++ standard states clearly what a pointer
to
an array is and how it behaves.
A pointer to a 2d array, when derefernced returns a 1d array subobject.
And that is a FACT defined in the C++ Standard.
It doesn't matter how much you try to worm your way around this fact,
it
is clearly defined in the standards and until you accept this fact you
will always be wrong.
You are the one spouting utter nonsense; the Standard says no such
thing. Dereferencing a pointer to a 2d array results in a reference to
a 2d array as the following code shows:
template <typename T, std::size_t N1, std::size_t N2>
void is_a_2d_array(T (&a)[N1][N2])
{
std::cout << "2D array; dimensions = " << N1 << " x " << N2;
}
int main()
{
char a[7][42]; // 2D array
char (*p)[7][42] =&a; // pointer to a 2D array
is_a_2d_array(*p); // dereferenced pointer to a 2D array is a 2D array
reference
}
According to the C++ standards when a 2d array is converted to a pointer
the pointer-type is a (n-1) dim array. Thus the correct conversion for a
2d array to a pointer is:
char a[7][7];
char (*pa)[7] = a;
pa above is *not* a pointer to a 2D array; it is a pointer to a 1D array.
No , it points to a 2d array.
Therefore it is a pointer to a 2d array. Its type is a pointer to a 1d array
because this is how pointers ot arrays work in C++.
You're POV that if something points to an array it is not a pointer to an
array is very confused and techincally inaccurate.
Indeed; this is implicit array-to-pointer conversion; nobody has said that
this is incorrect.
You are saying it doesn't point to a 2d array, so therefore you don't seem
to accept that this type of pointer is used to point to a 2d array.
Correct I have created an extra level of indirection to create a pointer
to a 2D array; without that extra level of indirection I would be creating
a pointer to a 1D array via implicit array-to-pointer conversion.
No you are talking about the pointer type but you use incorrect terminology.
When we say X is a pointer to an array this doesn't not mean the same as x
is a pointer-type pointer to an array.
The term "is a pointer to" refers to the pointed-to object and is not a term
that defines the pointer type for example:
void* p = (void*)new int[6];
p is a pointer to an array of 6 ints. p is not a pointer to void.