[fpc-devel] Fix for SwapEndian

Jonas Maebe jonas.maebe at elis.ugent.be
Tue Apr 29 15:53:47 CEST 2008


On 29 Apr 2008, at 15:41, Joost van der Sluis wrote:

> I've a problem with BeToN with smallints on a x86 system. When you use
> BeToN on smallint's with values like $8000 and $8200 it will return
> values like $FF80 and $FF82, instead or $0080 and $0082 respectively.
> The patch below fixes this, but I'm not sure if it's a correct fix, or
> that it's a bug in the compiler. (ie: is this behaviour of shr/shl
> normal on signed smallints?)

I don't know whether it's normal, but it's compatible with Delphi. I  
already fixed the same bug in r6752 (for swap() rather than for  
swapendian()).

I don't understand why we have both the swap() and swapendian()  
routines though, as this duplication (as demonstrated) can easily lead  
to unfixed bugs in one case or the other.


Jonas



More information about the fpc-devel mailing list