Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cuae2!ihnp4!houxm!mtuxo!mtune!mtund!adam From: adam@mtund.UUCP Newsgroups: comp.lang.c Subject: Re: Conversions/casts one more time Message-ID: <820@mtund.UUCP> Date: Thu, 11-Dec-86 05:20:44 EST Article-I.D.: mtund.820 Posted: Thu Dec 11 05:20:44 1986 Date-Received: Sun, 14-Dec-86 15:22:42 EST References: <176@unisoft.UUCP> Organization: AT&T ISL Middletown NJ USA Lines: 33 > (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 Ugh. %x expects an int, so the result of feeding it a char is, *and ought to be*, UNDEFINED. Adam Reed (mtund!adam)