标签: c++ arrays pointer-arithmetic strict-aliasing static-cast
此代码合法吗?它是否违反了严格的别名?它确实以预期的方式编译和工作。
using ARR3 = int [3]; using ARR2 = int [2]; ARR3 arr = {1, 2, 3}; ARR2 & off_by_1 = *static_cast<ARR2*>(static_cast<void*>(&(arr[1]))); std::cout << off_by_1[0] << std::endl;
打印出2