On Sat, 26 Jul 2003, James Mills wrote:

> Hi,
>
> Why does the following result in a runtime error ?
>
> program example;
>
> const
>       THE_PORT = 9999;
>
> function swapWord(w: Word): Word;
> begin
>       swapWord := (w SHL 8) OR (w SHR 8);
> end;
>
> var
>       port:   Word;
> begin
>       port := swapWord(THE_PORT)
> end.
>
> $ ./swapword
> Runtime error 201 at 0x08052AA2
>   0x08052AA2
>   0x08052AC2
>   0x080480B0

This is a range check error.
 (w SHL 8) OR (w SHR 8)
is evaluated as a longint. i.e. the result may not fit in a longint.
And I think it should be:
 ((w and $FF) SHL 8) OR (w SHR 8)

Michael.


_______________________________________________
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to