Conversions/casts one more time
Chris Torek
chris at mimsy.UUCP
Sun Dec 14 01:35:08 AEST 1986
>> printf("\tc = %x, (char)uc = %x, (char)ucf() = %x\n",
>> c, (char)uc, (char)ucf());
In article <820 at mtund.UUCP> adam at mtund.UUCP (Adam V. Reed) writes:
>Ugh. %x expects an int, so the result of feeding it a char is,
>*and ought to be*, UNDEFINED.
printf is also a function, so it is not possible to hand it a char.
`char' exists only as a data type (lvalue), not as an expression
type (rvalue), so `printf("%x", (char)c);' sends printf (int)(char)c,
not (char)c.
As to the original question, a cast is (supposed to be) equivalent
to an assignment to a temporary variable of the given type. The
printf() call above is therefore (supposed to be) equivalent to
char t1, t2;
t1 = uc;
t2 = ucf();
printf("\tc = %x, (char)uc = %x, (char)ucf() = %x\n",
c, t1, t2);
Whether this sign extends 0xaa is machine, and sometimes compiler,
dependent.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP: seismo!mimsy!chris ARPA/CSNet: chris at mimsy.umd.edu
More information about the Comp.lang.c
mailing list