<div dir="ltr"><div dir="ltr">On Fri, Sep 3, 2021 at 8:02 AM LacaK via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Can we say that in Pascal the result of:<br>
E1 shl E2<br>
is of same type as E1 ?<br>
(so if E1 is LongWord then result is LongWord also?)<br>
<br>
What if there is an expression on left side:<br>
(E1*x) shl E2<br>
Will E1*x promote to 64 bits (on 64 bit target)?<br></blockquote><div><br></div><div>See documentation on automatic type conversion (the remarks section below table 3.3): <a href="https://www.freepascal.org/docs-html/ref/refsu4.html#x26-26004r3">https://www.freepascal.org/docs-html/ref/refsu4.html#x26-26004r3</a></div><div>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.</div><div><br></div><div>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" (<a href="https://en.wikipedia.org/wiki/Word_(computer_architecture)">https://en.wikipedia.org/wiki/Word_(computer_architecture)</a>). 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.</div></div></div>