What's a C expert?

Eric Giguere jyegiguere at lion.waterloo.edu
Sat Jul 22 16:48:44 AEST 1989


In article <25999 at amdcad.AMD.COM> tim at amd.com (Tim Olson) writes:
> Having the sign of chars be undefined allows the implementation to be as
> efficient as possible with respect to converting between chars and ints.

In article <4724 at alvin.mcnc.org> spl at mcnc.org.UUCP (Steve Lamont) replies:
>                                                                   I
> thought the standard was supposed to clarify things, not confuse the
> issue.  It's almost like saying that a declaration of int may be either
> signed or unsigned.  Makes for somewhat unpredictable behavior and/or
> some fairly verbose defensive coding...

As someone else pointed out, part of the "Spirit of C" is to be as
efficient as possible without unduly constraining the users of the language...
hence a 'char' can be signed or unsigned depending upon which fits a  
particular machine best...

That said, the real reason why the pStandard does not specify that char  
should be signed or unsigned is that one of the overriding principles of
the ANSI document is to not invalidate current programming practice.... 
the "new" C should be as upwardly-compatible as possible with the "old" C.
Because many implementations had `char' as signed and many others had
it as unsigned, the Committee chose to do nothing about the ambiguity.  If
you want a signed type and are using ANSI compilers, used 'signed char'.
'unsigned char' should work on all current C compilers.... but to get a
signed char on some pre-ANSI machines you might actually have to fake it by
going up to a short...

Eric Giguere                                  268 Phillip St #CL-46
For the curious: it's French ("jee-gair")     Waterloo, Ontario  N2L 6G9
Bitnet  : GIGUERE at WATCSG                   (519) 746-6565
Internet: giguere at aries5.UWaterloo.ca         "Nothing but urges from HELL!!"



More information about the Comp.lang.c mailing list