[fpc-pascal]runtime 201 with swapword function

James Mills prologic at daisy.ods.org
Fri Jul 25 16:40:41 CEST 2003


On Fri, Jul 25, 2003 at 04:30:24PM +0200, Jonas Maebe wrote:
> 
> On vrijdag, jul 25, 2003, at 16:32 Europe/Brussels, James Mills wrote:
> 
> >>In Pascal, all calculations are performed using the base type (which 
> >>is
> >>longint in FPC), so if w > 255, then w shl 8 > high(word) and will
> >>result in a range check error when assigning to swapWord. Even if we
> >>calculated everything using words, you'd still get an overflow error,
> >>this time when doing the shl.
> >
> >How can I correct this ?
> 
> Use a typecast:
> 
> function swapWord(w: Word): Word;
> begin
> 	swapWord := Word((w SHL 8) OR (w SHR 8));
> end;

Excellent thank you :)

James

> 
> 
> Jonas
> 
> 
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

-- 
-
-Zero Defect Software Engineers Group - ZDSEG
-
-You need only two tools. WD-40 and duct tape.
-If it doesn't move and it should, use WD-40.
-If it moves and shouldn't, use the tape.




More information about the fpc-pascal mailing list