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