lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I said "in some context", not "in general". However

On 06/01/2023 08:51, bil til wrote:
If you would count this as "overflow/invalid", then presumably every
Lua (or C) Code like this also would show some overflow:
     i= 1 << 65;

this is most probably UB [1] unless, as Francisco Olarte said in his post, you have ints with 65 bits or more (presumably 128?).


Quite unusual even today on 64 bit system I guess, because otherwise "long" and "long long" would be probably redundant (OK, they could have still more bits, but a rare beast for sure, I guess).


... or e. g.
     i= 1
     while i do i= i<<1 ... some code... end

... but this clearly should be valid.



[1] C prohibits shifting for more than an integer object width. Citing from C99 draft standard (N1256; pag.84):

   6.5.7 Bitwise shift operators
[...]
   Semantics

   The integer promotions are performed on each of the operands. The
   type of the result is that of the promoted left operand. If the value
   of the right operand is negative or is greater than or equal to the
   width of the promoted left operand, the behavior is undefined.