Is casting a pointer to const pointer and cast back to the original type undefined?
问题 I know casting a const pointer to non-const type might be undefined behavior, but what if the pointer is originally not const? int i = 0; int * pi = &i; const int * const_pi = const_cast<const int*>(pi); int * non_const_pi = const_cast<int*>(const_pi); *non_const_pi = 0; *non_const_pi = 1; int j = *non_const_pi; Is there's any undefined behavior? If any, where do they happen? May the compiler assume that non_const_pi is casted from a const pointer and perform no modification? 回答1: I know