https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78809

--- Comment #40 from Wilco <wilco at gcc dot gnu.org> ---
(In reply to Qing Zhao from comment #39)
> > --- Comment #38 from Wilco <wilco at gcc dot gnu.org> ---
> > This uses signed char while the C standard says the comparison is done on
> > unsigned chars.
> > 
> 
> during my implementation, I did some research on whether I should use
> “unsigned char” or “signed char”
> for the comparison.  what I checked was man page of strcmp, memcmp, (I don’t
> have C standard in hand).
> in the manpage of memcmp, it clearly and explicitly mentioned that the chars
> are interpreted as unsigned char;
> however, in the manpage of strcmp/strncmp, it’s not mentioned at all.  So, I
> thought that for strcmp/strncmp,
> I should use signed char.  but for memcmp, I used unsigned char.
> 
> since I don’t have a C standard, could you please point me the corresponding
> section for this?
> thanks.

See eg. http://www.iso-9899.info/n1570.html section 7.24.4:

"The sign of a nonzero value returned by the comparison functions memcmp,
strcmp, and strncmp is determined by the sign of the difference between the
values of the first pair of characters (both interpreted as unsigned char) that
differ in the objects being compared."

Reply via email to