Is type punning arrays of same type but different size allowed?
问题 Is type punning arrays of the same type but with a different size still a violation of strict aliasing? int arr[4]; int(&ref)[2] = reinterpret_cast<int(&)[2]>(arr); arr[0] = 0; //write to original ref[0]; //read from pun 回答1: We can argue as follows; [expr.reinterpret.cast]/11: A glvalue expression of type T1 can be cast to the type “reference to T2 ” if an expression of type “pointer to T1 ” can be explicitly converted to the type “pointer to T2 ” using a reinterpret_cast . The result refers