type of character constants

Usenet Administration usenet at xyzzy.UUCP
Tue Mar 28 01:12:41 AEST 1989


In article <1989Mar18.221754.27335 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
| In article <1813 at dlvax2.datlog.co.uk> scm at datlog.co.uk ( Steve Mawer ) writes:
| >So what is the 'correct' value for '\377', 255 or -1?
| 
| Precisely! :-)  The correct value is "255 or -1".  If char is signed in
| the particular implementation, the value is -1 (assuming 8-bit chars);
| if char is unsigned, the value is 255.  The X3J11 rule is essentially
| that 'x' == (int)(char)'x' for all x, so it depends on whether conversion
| of char to int sign-extends.  Code that depends on one particular choice
| is non-portable.
From: meissner at bert.dg.com (Michael Meissner)
Path: bert!meissner

Warning, nit picking ahead....

Henry is of course right for just about any machine that you are
likely to run into, but two additional values are also possible.  If
you have a machine that uses one's complement, signed 8-bit bytes, you
would get back -0 for '\377'.  On the other hand, if you have a
machine that uses signed magnitude, signed 8-bit bytes, you would get
back -127 for '\377'.

The one's complement machines that I'm aware of are the Univac
mainframes, and the old Control Data Cybers (6xxx and 170 series).
The Univacs used 6, 8, and 9 bit bytes, dependending on the compiler,
and user options.  In terms of C, I believe they use 9 bit bytes,
since 8 bit bytes don't fit evenly in a 36-bit word.  The CDC machines
used 6 bit bytes, with a 12 bit extended code.  I don't think CDC ever
produced a C compiler for these machines, and their new machines (the
180 series) uses two's complement and 8 bit bytes in native mode,
though they do support the 170 series in some sort of emulation mode.

The only signed magnitude machine that I'm aware of is the Burroughs
mainframe (the A series and it's predecessors).  Given that they use
EBCDIC, I would suspect that they don't sign extend characters.  Also,
I believe that they have not yet released a C compiler, though I could
be wrong......

Michael Meissner, Data General.
Uucp:		...!mcnc!rti!xyzzy!meissner		If compiles were much
Internet:	meissner at dg-rtp.DG.COM			faster, when would we
Old Internet:	meissner%dg-rtp.DG.COM at relay.cs.net	have time for netnews?



More information about the Comp.lang.c mailing list