W
Why Tea
I understood that the CPU registers determine the size of the machine.
But what is the correct way to code an arithmetic operation to avoid
wrap-around when the code is to be run on both 32-bit and 64-bit
machines?
Example:
uint32_t x = SOME_LARGE_NO;
uint64_t y;
....
y = (uint64_t)(10000 * x); /* Will overflow occur before the cast? */
y = (int64_t)(x) * 10000; /* or, is it better to do the cast first?
*/
Please comment.
/Why Tea
But what is the correct way to code an arithmetic operation to avoid
wrap-around when the code is to be run on both 32-bit and 64-bit
machines?
Example:
uint32_t x = SOME_LARGE_NO;
uint64_t y;
....
y = (uint64_t)(10000 * x); /* Will overflow occur before the cast? */
y = (int64_t)(x) * 10000; /* or, is it better to do the cast first?
*/
Please comment.
/Why Tea