I understand that as of C++11, the conversion from int to unsigned long long is considered a narrowing conversion since unsigned long long cannot represent any negative values, despite being sufficiently large to represent all of the bits. My question is, if I force the conversion and then convert back to int, am I guaranteed to get the same value (specifically meaning that it is neither undefined nor implementation-defined behavior)?
int i = -42;
unsigned long long ull = static_cast<unsigned long long>(i);
int j = static_cast<int>(ull); // is this guaranteed to be -42?
Additionally, I would like to know about cases where only the signedness of the type is changed:
long long ll = -281474976710655LL;
unsigned long long ull = static_cast<unsigned long long>(ll);
long long n = static_cast<long long>(ull);
Are these values, j and n guaranteed to be the same as i and ll (respectively, of course)? Are there any portability or architecture (32 vs 64 bit) issues that need to be considered?