Subject: Re: Bad macros, locales (Was: Re: libedit 8bit clean)
To: None <current-users@NetBSD.ORG>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: current-users
Date: 03/06/1997 16:55:50
> The other thing I've encountered during trying to get it work: the
> macros in <ctype.h> do evil things for 8bit (i.e. >127) chars.

They're broken, then....

> I know the char tables in libc don't specify values for >127 chars
> anyway, but ...

That is _definitely_ broken.  The <ctype.h> macros are supposed to work
whenever the argument is either EOF or a value which is representible
as both an int and as an unsigned char.  (It may be less restrictive
than this; I don't have a copy of The Standard at hand.)

> Consider isprint('\355') [...] Defines in <ctype.h> expand it to:

>  ((_ctype_ + 1)['\355'] & (_P|_U|_L|_N|_B))

> BUT - for compiler '\355' equals to -19,

Well, only if you're using signed chars (possibly by default); in that
case, yes, the macro breaks - but it's the call that's broken, because
when signed 8-bit chars are in use, '\355' (which is, as you say, -19)
is not a value that can be taken on by both an int and an unsigned char
and hence passing that to isprint() is pilot error.

> Every subject to any <ctype.h> macro have to be casted to unsigned
> char to make it work correctly.

No, just make sure it's stored in an int, and was extended in a
value-preserving way from an unsigned char (eg, returned by getchar()).
Note that - at least according to the NetBSD manpage, and I feel sure
according to ANSI/ISO too - isprint() takes an int, not a char, as its
argument.

					der Mouse

			       mouse@rodents.montreal.qc.ca
		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B