On 06/16/10 10:11, hugo rivera wrote:
> Can someone clarify why the program included outputs 'AB000000' (as I
> expect) on 32 bit systems and 'FFFFFFFFAB000000' on 64 bit systems?
> where all those 1's came from? what's the portable way of doing this?
> sorry for newbie questions like this.
>
>
> unsigned long l;
> unsigned char c;
>
> l = 0L;
> c = 0xAB;
> l |= c << 24;
> printf("%lX\n", l);
>
>
check the ASM, looks like c is being cast as signed and then sign
extended into a long and then ORed with l.
perhaps this would solve it :
l |= ((unsigned long) c) << 24
But I can't check