Conversions/casts one more time

Wendy Thrash wendyt at unisoft.UUCP
Sat Dec 13 11:29:52 AEST 1986


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.



More information about the Comp.lang.c mailing list