3 ms·
> Carry: "if (x + y < x)" compiles to code that uses the carry flag. If x and y are signed, you're relying on UB, which the compiler might optimize out. > "if
by zvrba 14y ago
> Carry: "if (x + y < x)" compiles to code that uses the carry flag.
If x and y are signed, you're relying on UB, which the compiler might optimize out.
> "if ((int32_t) (x + y) < 0)" compiles to code that uses the overflow flag.
Again, which type are x and y? If signed, this code is UB. If unsigned, then the result of conversion to int32 may not fit into int32, in which case the result is implementation-defined, or and implementation-defined signal is raised.
Portable? Right.