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 <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.


But look at Delphi documentation: https://docwiki.embarcadero.com/RADStudio/Sydney/en/Expressions_(Delphi)#Logical_.28Bitwise.29_Operators

"The operations x shl y and x shr y shift the value of x to the left or right by y bits, which (if x is an unsigned integer) is equivalent to multiplying or dividing x by 2^y; the result is of the same type as x"

My understanding is, that in case:
E1 shl E2 result is of E1 type (so if E1 is LongWord on 64 bit platform result is still LongWord?)

Case
  (E1*x) shl E2 is subject to native integer promotion I guess?

L.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to