delete[] p or delete[] *p

G

Goran

No your conclusion is nonsense, the same pointer can point to a single int
or and array of int. If you assign to it the address of an array, then it
points to an array. If you assign to it the address of a single int, thenit
points to a single int.

If you assign to it the address of an array, then we __commonly say__
that it points to an array. If you assign to it the address of a
single int, then it points to a single int.

FTFY.

You want to conflate "points to" and "is". We commonly do that out of
expedience, but giving any more meaning to that leads to bugs,
horrible and/or easily misunderstood code, which is what you yourself
have done on several occasions in the beginning of this thread.
Therefore such conflating is unwarranted.

Goran.
 
P

Paul

If you assign to it the address of an array, then we __commonly say__
that it points to an array. If you assign to it the address of a
single int, then it points to a single int.

No we don't normally take the address of an array , using the address&of
operator. Doing this creates an extra level of indirection show by
comparison to pointer to int:

int x;
int arr[4];

/*create pointers*/
int* p_x = &x; /*pointer to integer*/
int* p_arr = arr; /*pointer to array*/

/*create another level of indirection*/
int** pp_x = &p_x;
int (*pp_arr)[5] = &arr;
int** pp_p_arr = &p_arr;

The above two array pointers are at the same level of indirection. The
difference is what happens when you..
a) dereference them
b) increment them

They both point to exactly the same memory loaction(where the array has been
allocated). The pointer-type allows the compiler to know how many bytes of
memory will be addressed when the pointer is derefernced



You want to conflate "points to" and "is". We commonly do that out of
expedience, but giving any more meaning to that leads to bugs,
horrible and/or easily misunderstood code, which is what you yourself
have done on several occasions in the beginning of this thread.
Therefore such conflating is unwarranted.

I don't know what you are trying to say here. What "points to" generally
means is what has been allocated at the pointed to memory.
 
G

Goran

Ok, so it's a fact that it's a pointer to an array. And one can assign
address of a single int to it, too (that's a fact, too). So pointer is
now not a pointer to an array.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
This would be correct.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

This implies that what pointer is, i.e. it's type, changes. Given that
C and C++ are statically typed languages, that can't be correct.
Consequently, claim that pointer changes it's type is incorrect.

What is correct, though, is that, out of expedience, we __commonly
say__ that pointer __is__ a point to an array.

Goran.
 
G

Goran

Ok, so it's a fact that it's a pointer to an array. And one can assign
address of a single int to it, too (that's a fact, too). So pointer is
now not a pointer to an array.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
This would be correct.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 Therefore, your fact is in conflict
with itself. Therefore, your fact is nonsense.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
No your conclusion is nonsense, the same pointer can point to a single int
or and array of int.

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).

Goran.
 
P

Paul

Ok, so it's a fact that it's a pointer to an array. And one can assign
address of a single int to it, too (that's a fact, too). So pointer is
now not a pointer to an array.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
This would be correct.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Therefore, your fact is in conflict
with itself. Therefore, your fact is nonsense.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
No your conclusion is nonsense, the same pointer can point to a single int
or and array of int.

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?

Or do you somehow feel that you are equally as special as cg_chas and its
quite ok for you to dismiss Stroustrup and others experts as bullshitters
who dont know what they're talking about?
 
G

Goran

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 arrayof
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.

Goran.
 
P

Paul

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?

Also do you accept what is detailed int he C++ standards where it clarifies
that a pointer to an array, when dereferenced , returns an (n-1) dim array?
 
P

Paul

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

Now if Bjarne says one thing and you say it is incorrect, then who is more
likely to be wrong?
Additionally if the C++ standards defines something and you say its
incorrect, then who is more likely to be wrong?
 
P

Paul

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.
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;

You take the address of a thus introducing an unneccessary extra level of
indirection.

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.

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

Paul

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

You are confused by the pointer-type and what it points to.
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.
 
C

crisgoogle

[snip]
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 pointsto
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.

No, the standard says that a 2d array (NOT a _pointer_ to a 2d array,
but just
a 2d array) will be converted to a pointer to 1d array, and this
pointer-to-
1d-array, when dereferenced, yields (of course) a 1d array.

Read 8.3.4p7 a little more carefully. If this isn't your reference
(and it
_is_ the one you've used in the past), then what part of the standard
supports
your claim?
 
I

Ian Collins

Your understanding is flawed, the C++ standard defines a pointer to a 2d
array to be of this type/ level of indirection.

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.

Come on, get it right. Is there one standard that defines the C++
language or more than one? Which sections on the mythical other
language (not library extension) standard are you referring to?

Citations, please.
 
P

Paul

Ian Collins said:
Come on, get it right. Is there one standard that defines the C++
language or more than one? Which sections on the mythical other language
(not library extension) standard are you referring to?

Citations, please.
8.3.4 Arrays
7 A consistent rule is followed for multidimensional arrays. If E is an
ndimensional
array of rank
i´ j´ . . . ´k, then E appearing in an expression is converted to a pointer
to an (n - 1 )dimensional
array
with rank j´ . . . ´k. If the * operator, either explicitly or implicitly as
a result of subscripting, is applied to
this pointer, the result is the pointedto
(n - 1 )dimensional
array, which itself is immediately converted
into a pointer.
 
P

Paul

crisgoogle said:
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.
No, the standard says that a 2d array (NOT a _pointer_ to a 2d array,
but just
a 2d array) will be converted to a pointer to 1d array, and this
pointer-to-
1d-array, when dereferenced, yields (of course) a 1d array.

Yes it says exactly what I say.

The following is a 2d array converted to a pointer:
char arr[8][8];
char (*p)[8] = arr;

The pointer is a pointer to a 2dim array, its type is pointer to (2-1)dim
array so that when its dereferenced it returns an (n-1) dim array. That is
how pointers to arrays work in C++ and its explained so in the C++
standards.

The above is how an array is converted to a pointer the following is
possible but not what is generally meant by array to pointer conversion:
char (*pp)[8][8] = &arr;
This is not what happens when an array is converted to a pointer.
Similarly with 1d arrays:
char arr[8];
char* p = arr; /*Convert array to pointer*/
char (*p)[8] = &arr; /*Differs in level of indirection , not a standard
conversion.*/


According to the C++ standard the correct terminology for array to pointer
conversion is exactly what I have said.
An array of 10 chars , when converted to a pointer, is of pointer-type
char* , not char (*p)[10].


Read 8.3.4p7 a little more carefully. If this isn't your reference
(and it
_is_ the one you've used in the past), then what part of the standard
supports
your claim?

I quote the section below , it fully explains how arrays work in C++.

"8.3.4 Arrays
7 A consistent rule is followed for multidimensional arrays. If E is an
ndimensional
array of rank
i´ j´ . . . ´k, then E appearing in an expression is converted to a pointer
to an (n - 1 )dimensional
array
with rank j´ . . . ´k. If the * operator, either explicitly or implicitly as
a result of subscripting, is applied to
this pointer, the result is the pointedto
(n - 1 )dimensional
array, which itself is immediately converted
into a pointer."
 
P

Paul

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.
That was just gibberish.


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.

As you say a char* can only point to a single char and cannot point to an
array of chars.
But when I post quotations from Stroustrup and the C Faqs , you start to
look stupid.

You are inconsistent and seem confused.
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;
The C++ standard explains this is how a 2d array is converted to a pointer,
so that when dereferenced it returns a 1d array(one of its subarrays).

What you have done is not a standard array-pointer conversion. You have
created an extra level of indirection.
 
G

Goran

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.

I accept, no problem. He is not saying that a char* __is__ a pointer
to an array of char, he is saying that it can __point to__.

He is merely using common expedient way of talking about these things,
where we say that TYPE*, when it points to the __first element__ of
the array, points to the __array__.
Also do you accept what is detailed int he C++ standards where it clarifies
that a pointer to an array, when dereferenced , returns an (n-1) dim array?

I don't know what part of standard are talking to, but I am pretty
sure that you are wrong. It rather returns a __reference to same-
dimension array__, e.g.:

void f()
{
int a[2][2]; // 2 dim array
int (*p)[2] = &a[0]; // pointer to 1d array.
int (&br)[2] = *p; // dereferencing returns a reference to a 1d array.
}

Goran.
 
G

Goran

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.
No, the standard says that a 2d array (NOT a _pointer_ to a 2d array,
but just
a 2d array) will be converted to a pointer to 1d array, and this
pointer-to-
1d-array, when dereferenced, yields (of course) a 1d array.

Yes it says exactly what I say.

The following is a 2d array converted to a pointer:
char arr[8][8];
char (*p)[8] = arr;

The pointer is a pointer to a 2dim array, its type is pointer to (2-1)dim
array so that when its dereferenced it returns an (n-1) dim array.

OK, so... p is a pointer to a 2d array, but it's __type__ is a pointer
to 1d array. That's the first time I have heard of such a distinction
in this context. So what is the difference between "X is" and "type of
X is"? (I'll tell you: there's no distinction, and p __is__ what its
type is, and that is a pointer to 1d array. And because at runtime p
points to the first element of arr, we __commonly say__ that it points
to arr).

Goran.
 
P

Paul

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.
No, the standard says that a 2d array (NOT a _pointer_ to a 2d array,
but just
a 2d array) will be converted to a pointer to 1d array, and this
pointer-to-
1d-array, when dereferenced, yields (of course) a 1d array.

Yes it says exactly what I say.

The following is a 2d array converted to a pointer:
char arr[8][8];
char (*p)[8] = arr;

The pointer is a pointer to a 2dim array, its type is pointer to (2-1)dim
array so that when its dereferenced it returns an (n-1) dim array.

OK, so... p is a pointer to a 2d array, but it's __type__ is a pointer
to 1d array. That's the first time I have heard of such a distinction
in this context. So what is the difference between "X is" and "type of
X is"? (I'll tell you: there's no distinction, and p __is__ what its
type is, and that is a pointer to 1d array. And because at runtime p
points to the first element of arr, we __commonly say__ that it points
to arr).

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

So what is
a) Your confusion
b) your argument?


As far as I am aware you , like the others , beleive that with a simple 1d
array:
int* p= new int[6];
p is a pointer to a single int and not a pointer to the array. But
according tot he standards, Bjarne and C FAQs, a pointer to a 1d array is
exactly the same type of pointer as a pointer to a single element.


So what exactly is your disagreement with this? Why do you have a problem
accepting this is the way pointers to arrays work in C++?
If you are just going to continue arguing because you cannot accept that
you're wrong, then lets clarifiy what exactly are you trying to argue about
now? What is your argument now exactly, the definition of the word "is" or
some other bullshit?
 
P

Paul

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.

I accept, no problem. He is not saying that a char* __is__ a pointer
to an array of char, he is saying that it can __point to__.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Do you accept that the char* points to an array of chars or not?
Do you accpet that
int* p = new int[7];

p points to an array of ints?

If you do shut up and accept defeat. If you don't shut up you are wrong.
 
G

Goran

I accept, no problem. He is not saying that a char* __is__ a pointer
to an array of char, he is saying that it can __point to__.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Do you accept that the char* points to an array of chars or not?

I accept that we __commonly say__ that, when such pointer points to
the first element of an array, it points to the array. Underlying
truth is, though, that such pointer __is__ a pointer to a __single__
array element (here, first).

Goran.
 

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,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top