> From: Jim Meyering <j...@meyering.net> > Cc: arn...@skeeve.com, bug-grep@gnu.org > Date: Mon, 03 Oct 2011 13:27:12 +0200 > > > I get a negative value for 0x95 from `lex'. An explicit `fprintf' > > after this line: > > > > (c) = wctob(wc); > > > > shows that the value of `c' is -107. The value returned by wctob, if > > printed using %d is -107, and if printed with %x, shows as 0xffffff95. > > That shows the problem is with the Windows wctob implementation.
What is the problem with it? > What if you include something like this just above? > (this is part of gnulib's wctob replacement, lib/wctob.c) This version of wctob solves the problem. But I'd still like to understand what is wrong with stock wctob, as the references I consulted don't say the result must be positive. E.g., this: http://pubs.opengroup.org/onlinepubs/007904875/functions/wctob.html says The wctob() function shall return EOF if c does not correspond to a character with length one in the initial shift state. Otherwise, it shall return the single-byte representation of that character as an unsigned char converted to int. Does "unsigned char converted to int" necessarily say that the result must be positive? Or am I missing something? Thanks.