Browse Source

Merged revisions 6752 via svnmerge from
svn+ssh://[email protected]/FPC/svn/fpc/trunk

........
r6752 | jonas | 2007-03-08 23:30:12 +0100 (Thu, 08 Mar 2007) | 3 lines

* fixed swap(integer) due to counter-intuitive TP/Delphi compatible
shr-behaviour

........

git-svn-id: branches/fixes_2_2@6755 -

Jonas Maebe 18 years ago
parent
commit
a8365437c2
1 changed files with 5 additions and 1 deletions
  1. 5 1
      rtl/inc/system.inc

+ 5 - 1
rtl/inc/system.inc

@@ -190,7 +190,11 @@ End;
 
 Function Swap (X : Integer) : Integer;{$ifdef SYSTEMINLINE}inline;{$endif}
 Begin
-  swap:=(X and $ff) shl 8 + (X shr 8)
+  { the extra 'and $ff' in the right term is necessary because the  }
+  { 'X shr 8' is turned into "longint(X) shr 8", so if x < 0 then   }
+  { the sign bits from the upper 16 bits are shifted in rather than }
+  { zeroes. Another bug for TP/Delphi compatibility...              }
+  swap:=(X and $ff) shl 8 + ((X shr 8) and $ff)
 End;
 
 Function swap (X : Longint) : Longint;{$ifdef SYSTEMINLINE}inline;{$endif}