gcc
is right here and the diagnostic is required in C.
double da[ 3 ] = { 2., 3., 4. };
double (* pda)[ 3 ] = &da;
double const (* cpda)[ 3 ] = pda; // diagnostic here
Basically you are trying to assign an object of type T1
to an object of type T2
(constraints of simple assignment apply for initializations).
Where T1
is a pointer to an array N
of T
.
And T2
is a pointer to an array N
of const T
.
In the constraints of the simple assignment, C says that for pointers the following shall hold (in C99, 6.5.16.1p1):
both operands are pointers to qualified or unqualified versions of compatible types, and the type pointed to by the left has all the qualifiers of the type pointed to by the right
This would allow for example something like:
int a = 0;
const int *p = &a; // p type is a qualified version of &a type
But in your example, a pointer to an array N
of const T
is not a qualified version of a pointer to an array N
of T
. In C an array cannot be constant: there is not const
arrays, but only arrays of const
elements.