Conversion between signed integer and unsigned integer
问题 If I cast an unsigned integer to a signed integer then cast back, am I guaranteed to get the original value? For example, does this function always return true for any x on any platform according to the C++ standard? bool f(unsigned int x) { return x == static_cast<unsigned int>(static_cast<int>(x)); } What about this one? bool g(int x) { return x == static_cast<int>(static_cast<unsigned int>(x)); } 回答1: The answer is "no, this is not guaranteed" for both f and g . Here is what the standard