type casting problem - (nf)
johnl at ima.UUCP
johnl at ima.UUCP
Sat Jun 11 08:35:49 AEST 1983
#R:decvax:-11200:ima:15900008:000:997
ima!johnl Jun 10 12:28:00 1983
Some more recent C compilers implement an "unsigned char" data type.
Characters are never required to be signed, the manual explicitly says
that it's machine dependent.
So, in any case, the morally correct thing to do to ensure unsigned
characters is to declare your pointer to them to be "unsigned char." Of
course, this won't work on half of the C compilers that really exist. If
you want to be sure, you have to write something like:
i = *cp++ & 0377;
This is clearly an artifact of C being used mostly on PDP-11s in its
early years. The 11 is the only machine around (that I know of) that
prefers signed chars, due to sign extension in the "mov" instruction.
Some machines prefer unsigned chars, e.g. the IBM 370 series. Some swing
either way, e.g. the Vax and the 8086. I expect that as Unix runs
predominantly on other than 11's and Vaxen, signed characters will wither
away.
John Levine, decvax!yale-co!jrl, ucbvax!cbosgd!ima!johnl,
{research|alice|allegra|floyd|amd70}!ima!johnl
More information about the Comp.lang.c
mailing list