Signed char - What Foolishness Is This!

Doug Gwyn gwyn at brl-smoke.ARPA
Sun Oct 19 12:08:52 AEST 1986

In article <8719 at duke.duke.UUCP> jwg at duke.UUCP (Jeffrey William Gillette) writes:
>     #define isupper(c)     ( (_ctype+1)[c] & _UPPER )
>The problem here lies with Microsoft.

No, the problem lies with the programmer.  The is*() functions have
(int), not (char), arguments.  When you feed one a (char), it will
be promoted to an (int) by the usual rules, including possible sign
extension.  The macro definition acts the same as a function in this
regard, since array indices are (int), not (char), also.  Microsoft's
definition is correct.

>1)      Do other C compilers make 'char' a signed quantity by default?

Dennis Ritchie's original (PDP-11) C compiler did.

>2)      What possible justification is there for this default?

(a) less cost on machines like the PDP-11

(b) the programmer can, using suitable code, force whatever behavior
	he wants

>I mean is, what is the definition of a negative 'a'?

It might surprise you to learn that 'a' represents an (int) constant,
not a (char).  C (char)s are just short integral types whose signedness
depends on the implementation (however, (signed char) and (unsigned char)
have definite signedness).  Dennis intended that sizeof(char)==1 but
I can make a strong argument that that isn't necessary.

P.S.  I suggest people learn what is going on before raving about it.
That would sure reduce the noise level of net.lang.c.

More information about the Comp.lang.c mailing list