...
This compliant solution uses the largest unsigned integer type available, if it is guaranteed to hold the result. If it is not, another solution must be found, as discussed in INT32-C. Ensure that integer operations on signed integers do not result in an overflow.
| Code Block | ||
|---|---|---|
| ||
#if UINT_MAX > UINTMAX_MAX/UINT_MAX #error No safe type is available. #endif /* ... */ unsigned a, b; uintmax_t c; /* ... */ c = (uintmax_t)a * b; /* guaranteed to fit, verified above */ |
...