Conversions/casts one more time

Wendy Thrash wendyt at unisoft.UUCP
Tue Dec 9 10:13:53 AEST 1986


(Sorry if this has been asked before; my memory is sometimes [unsigned] short.)

When I compile and run the program below, I expect to get the same answer
three times.  On our 11/750 under 4.3 BSD, I get
	c = ffffffaa, (char)uc = ffffffaa, (char)ucf() = aa
Seems to me that I ought to get ffffffaa for all three.

Questions:
1) Am I missing something, or did the BSD compiler just drop a conversion?
2) Is this sort of thing supposed to be implementation dependent?
3) My July '86 version of the X3J11 draft says (in 3.3.4), "A cast that
   specifies an implicit conversion or no conversion has no effect on the
   type or value of an expression."  What the heck does that mean, really?
   Does it have anything to do with questions 1) and 2)?

----
unsigned char ucf() { return 0xaa; }

main() {
	char c;
	unsigned char uc = 0xaa;

	c = uc;
	printf("\tc = %x, (char)uc = %x, (char)ucf() = %x\n",
	  c, (char)uc, (char)ucf());
}
----
Wendy Thrash -- UniSoft Corporation
{ucbvax,lll-lcc,sun}!unisoft!wendyt



More information about the Comp.lang.c mailing list