[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: fossil build failure on riscv64



"Barak A. Pearlmutter" <barak@pearlmutter.net> writes:

> Okay. So can I ask what *is* the correct way to do this: [...]
> and be able to rely on (u%10) being non-negative?

One way would be to make u a wider type (e.g. uint64_t), so it can
represent the negation of INT_MIN. On rv64 it'll be just as efficient
because it was using 64-bit registers to hold the 32-bit values anyway,
although I guess it'll produce worse code on 32-bit platforms. This
seems to be what glibc and musl do in their printf implementations.

You could also keep the existing code, but special-case INT_MIN
first. But the simplest fix would be to scrap the custom int-to-string
code entirely, and just do something like snprintf(zBuf, sizeof zBuf,
"%d", iVal)...

Thanks,

-- 
Adam Sampson <ats@offog.org>                         <http://offog.org/>


Reply to: