Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!clyde!burl!codas!mtune!mtund!adam From: adam@mtund.UUCP (Adam V. Reed) Newsgroups: comp.lang.c Subject: Re: Re: Conversions/casts one more time Message-ID: <825@mtund.UUCP> Date: Tue, 16-Dec-86 22:15:17 EST Article-I.D.: mtund.825 Posted: Tue Dec 16 22:15:17 1986 Date-Received: Thu, 18-Dec-86 00:00:29 EST References: <176@unisoft.UUCP> <820@mtund.UUCP> <179@unisoft.UUCP> Organization: AT&T ISL Middletown NJ USA Lines: 39 > Keywords: > > My program: > >> 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()); > >> } > > Adam Reed (mtund!adam) writes: > >Ugh. %x expects an int, so the result of feeding it a char is, > >*and ought to be*, UNDEFINED. > > Golly! Guess they've changed the language on me again. Last I heard, > char variables were converted to int whan passed as parameters. That meant > that when I did something like this I could see what the compiler produced > when it converted the expression to int. Guess I'll have to go back to writing > int i, j, k; > ... > i = c; > j = (char)uc; > k = (char)ucf(); > and looking at the result with adb. It's SO hard to keep up with these things! > > In case anyone wonders, the point of this question was that the 4.3 VAX C > compiler sometimes throws away casts when it's doing promotions. I don't > believe this is correct, and those who have addressed that issue (by mail as > well as by posting) have agreed. Thanks to all of you who wrote. Alternatively, and as I assumed, casting an argument may be interpreted by your compiler as a directive to promote it to the type specified by the cast, instead of the default (K&R p.24) int. Given the obvious utility of such a feature, I still suspect that this is what it does. Could you check? Adam Reed (mtund!adam)