[fpc-pascal] Conversion from C to Pascal - Left bit shift
Christo Crause
christo.crause at gmail.com
Fri Sep 3 09:58:28 CEST 2021
On Fri, Sep 3, 2021 at 8:02 AM LacaK via fpc-pascal <
fpc-pascal at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210903/bb2b4c49/attachment.htm>
More information about the fpc-pascal
mailing list