is it specified in standard that array of const elements has different type than array of non-const elements? Here is my code and output of VC2010 and GCC4.8.0.
Thank you.
#include <iostream>
#include <typeinfo>
#include <ios>
int main(){
int arr_a[] = {1, 2};
int const arr_b[] = {3, 4}; // or const int arr_b[] = {3, 4};
std::cout << typeid(arr_a).name() << "\n";
std::cout << typeid(arr_b).name() << "\n";
std::cout << "Same type: " << std::boolalpha << (typeid(arr_a) == typeid(arr_b)) << ".\n";
}
int [2]
int const [2]
Same type: false.
A2_i
A2_i
Same type: true.
The C++11 standard actually says (3.9.3/1) (emphasis mine)
[...] The cv-qualified or cv-unqualified versions of a type are distinct types; however, they shall have the same representation and alignment requirements
with the following precision:
The same representation and alignment requirements are meant to imply interchangeability as arguments to functions, return values from functions, and non-static data members of unions
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