Joe Wright wrote:
> jacob navia wrote:
>> Joe Wright wrote:
>>> jacob navia wrote:
>>>> santosh wrote:
>>>>>> I have changed the code as below
>>>>>>
>>>>>> #include <stdio.h>
>>>>>> int main(void)
>>>>>> {
>>>>>> int x = 0x7fff;
>>>>>> signed char y;
>>>>>> y =(signed char) x;
>>>>>> printf("%hhx\n", y);
>>>>>> return 0;
>>>>>>
>>>>>>
>>>>>> }
>>>>>> Now is it guaranteed that y will hold ff which is the last byte of
>>>>>> x ?
>>>>>>
>>>>>> Now the output is ffffffff
>>>>>> Why it is not ff only ?
>>>>>
>>>>> I get 'ff' here. What compiler are you using and what are the options
>>>>> that you are passing it?
>>>>>
>>>>
>>>> I get ff here too
>>>>
>>> I took the liberty of changing the code again..
>>>
>>> #include <stdio.h>
>>> int main(void)
>>> {
>>> int x = 0x7fff;
>>> char y;
>>> y = x;
>>> printf("%hx\n", y);
>>> return 0;
>>> }
>>> None of the casting was necessary and "%hhx" is weird. This prints
>>> ffff just as I expect it to. What is the case for ff?
>>>
>>
>> See my other reply. I think Microsoft has a bug here
>>
> My compiler is gcc (djgpp) and I get ffff. If msvc gets ffff too I don't
> see the 'bug' you suggest. Once x is assigned to y the value of y is -1.
> In the printf the value of y is promoted to int (still -1) and displayed
> as unsigned short (ffff). In order to print ff the value of y must be
> 255 and there is no case for that here. Could be lcc-win is broke.
>
I was speaking about the second version, and did not see that you
have changed it AGAIN. After that change I get ffff again.
The bug I was referring to was for this code
#include <stdio.h
int main(void)
{
int x = 0x7fff;
signed char y;
y =(signed char) x;
printf("%hhx\n", y);
return 0;
}
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32