Mail Archives: djgpp-workers/1998/02/13/02:10:40
Vik Heyndrickx wrote:
> Doesn't the standard say that any values represented in a smaller type,
> should have the same value when promoted to a larger type which can
> contain all values from that smaller type. Borland is very wrong.
>
> The gnu compiler is right.
> It first sign-extends the smaller signed type to the equivalent 'signed'
> version of the larger type and then "turns the signedness" to the one of
> the destination type. This is also the case for unsigned types being
> promoted (sign-extension is zero-extension in this case)
I have no idea about the standard (never seen it), but *I* feel that gcc
is right. To me, it seems that a signed variable sould be sign extended
and unsigned zero extended. It just doen't make sence any other way.
>
> > unsigned char byte=0xff;
> > long dword=byte;
> > printf("%ld\n",dword);
> >
> > would print -1, even if the second line was changed to "long
> > dword=(unsigned char)byte;". I can't remeber how we fixed this
>
> Very, very, wrong. You can easily fix this by buying another compiler.
> Strange that is wasn't even a M$ product :-)
:)
Has anybody ever checked this with a M$ compiler? I'm actually curious
what MSC or VC++ does (I'ld be pleasantly supprised it it got it
right)..
Bill
--
Leave others their otherness.
- Raw text -