I have an unsigned value that should go through the function as a signed value (this will not affect the function). When he comes out, I return him without a sign. I know that the result of the casting to signing is an implementation defined during overflow, but can I at least guarantee that I get the same value when I return it (for example, with function pointers)?
Example:
int32_t function_with_default(int32_t a_Default) { // Try some stuff // ... // Fall back to default return a_Default; } void main() { uint32_t input = UINT32_MAX; uint32_t output = static_cast<uint32_t>(function_with_default(static_cast<int32_t>(input)); // Is is guarenteed to be true? input == output; }
I have guarentee that a signed integer is always greater than or equal to an unsigned integer in bytes, so no data should be lost due to lack of space.
source share