On 4/6/21 12:23 PM, Marc Nieper-Wißkirchen wrote:
Where is the flaw in my reasoning?
Oh, you're right; any nonnegative signed integer value will fit into uintmax_t. (Perhaps this wasn't always true in older standards, but it's true of the recent C standard.)
So that cast should work. Still, I wouldn't use a cast; I'd assign the integer to an uintmax_t local value, and use that.
And anyway, for this particular case widening to uintmax_t is not necessary; it complicates the code and can make it less efficient on some platforms by forcing an unnecessary conversion at runtime. So let's not do that.