Everybody knows how to declare an array with constant elements:
const int a[10];
Apparently, it is also possible to declare an array that is itself constant, via a typedef
:
typedef int X[10];
const X b;
From a technical and a practical standpoint, do a
and b
have the same type or different types?
Apparently, it is also possible to declare an array that is itself constant
Nope. In N1256, §6.7.3/8:
If the specification of an array type includes any type qualifiers, the element type is so-qualified, not the array type.118)
Then footnote 118 says:
Both of these can occur through the use of
typedefs
.
They have the same type, though clang will print them differently. Since the array itself cannot be const
, it is said to "fall through".
For the non-typedefed version, clang prints the type as const int [10]
. For the typedef version, it prints int const[10]
. Both of those are equivalent.
Coliru in action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With