[fpc-devel] Unexpected behaviour of bit operators

Marco Borsari borsa77 at libero.it
Mon May 20 11:24:16 CEST 2019

On Fri, 17 May 2019 18:06:13 +0200
Ondrej Pokorny <lazarus at kluug.net> wrote:

> On 17.05.2019 10:47, Marco Borsari via fpc-devel wrote:
> > Does this is an effect of some multiplication overflow, or is it a bug?
> Both the bit operations and the arithmetic opretaions return integers as 
> results and not words:
> https://www.freepascal.org/docs-html/ref/refsu46.html
> https://www.freepascal.org/docs-html/ref/refsu45.html#x148-17000012.8.1
> The c:=... overflows - you get a range check error:
> c:=(a XOR b)*(a SHL 5+b SHR 2); // range check error
> Just add a couple of word() casts where you need the integer-result to 
> be casted to word:

I tested it (the hash is used for a contest selector in a data
compressor), but it seems that the results are bit identical with or
without the cast. Do you point it out to suppress false positives in a
debug phase? Anyway, thank you.
Simplex sigillum veri

More information about the fpc-devel mailing list