On Fri, Sep 3, 2021 at 8:02 AM LacaK via fpc-pascal <
fpc-pascal@lists.freepascal.org> wrote:

> Can we say that in Pascal the result of:
>    E1 shl E2
> is of same type as E1 ?
> (so if E1 is LongWord then result is LongWord also?)
>
> What if there is an expression on left side:
>    (E1*x) shl E2
> Will E1*x promote to 64 bits (on 64 bit target)?
>

See documentation on automatic type conversion (the remarks section below
table 3.3): https://www.freepascal.org/docs-html/ref/refsu4.html#x26-26004r3
While this doesn't explicitly mention shift behaviour, it implies that E1
and (E1*x) will be promoted to native sized integer if smaller.  For the
first example, if E1 is a longword on a 32 bit machine, the result should
also be a longword.

Personal note:  I find the naming of ordinal types confusing.  Is shortint
smaller than smallint, or smallint shorter than shortint? In FPC a word is
2 bytes in size, however on the hardware side a word refers to "the natural
unit of data used by a particular processor design" (
https://en.wikipedia.org/wiki/Word_(computer_architecture)).  I prefer to
use the type aliases with explicit mention of size, such as int16, uint8
etc. I assume the flip side of this is when trying to write portable code
that uses the most efficient size available on a target.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to