[PATCH] Add cast to unsigned char to strverscmp
Christian Franke
Christian.Franke@t-online.de
Fri Nov 8 18:12:15 GMT 2024
Hans-Bernhard Bröker wrote:
> Am 08.11.2024 um 12:41 schrieb Christian Franke:
>> Corinna Vinschen wrote:
>>> On Nov 7 13:58, Joel Sherrill wrote:
>
>>> Given that l and r are unsigned char anyway, the entire expression
>>> is unsigned, so there shouldn't be a sign-compare error in newlib's
>>> version.
>
>> It's actually signed, IIRC due to changing 'unsigned preserving' (K&R
>> C) to 'value preserving' (C89) implicit conversions.
>
> The reason it's signed is because '1' is a signed integer, so this
> expression has a type train of:
>
> ((unsigned char) - (signed int)) < (unsigned int)
The LHS of '<' is signed because both arguments are signed after
implicit integer promotion:
((signed int)(unsigned char) - (signed int)) < (unsigned int)
In traditional K&R C, it was unsigned:
((unsigned int)(unsigned char) - (signed int)) < (unsigned int)
More information about the Newlib
mailing list