int32_t x = (int32_t)y; not overflowing, not UB. Overflow is when an arithmetic operation returns a result outside the range of the represented values. However, the conversion is not an arithmetic operation.
This situation is determined by behavior. All implementations that I know define behavior as not changing the view.
Please note that no cast is required here. You can write int32_t x = y; . In practice, this is simpler and will always work. So much code relies on this that no vendor is ever going to define any other behavior (and not that they have every reason for this anyway).
int32_t x = *(int32_t*)&y not UB. It does not violate a strict alias because a signed version of a type is allowed for aliases of an unsigned version. This code is guaranteed to create int32_t with the same representation as the corresponding uint32_t (ie, "Wrap", as these types are guaranteed to be 2 additions).
MM
source share