[fpc-devel] Do bitwise operation (1 or 2) acre about the sign ? (Giving sign related hints on compilation)
Martin
lazarus at mfriebe.de
Mon Jan 14 15:10:24 CET 2013
On 14/01/2013 13:54, ik wrote:
> On Mon, Jan 14, 2013 at 3:11 PM, Martin <lazarus at mfriebe.de> wrote:
>> Actually not so much about the hint, as about the fact that in the below
>> example fpc extends the operands to 64 bits.
>>
>> program Project1;
>> var
>> x: cardinal;
>> i, j: integer;
>> begin
>> i:= x or j
>> end.
> i is an "integer" type, and you try to assign it a number that might
> have 64 bit value.
> It might overflow the memory itself.
>
That is not it.
program Project1;
var
x: cardinal;
j: integer;
i: qword; // int64;
begin
i:= x or j
end.
Happens too, if the left site is int64 or qword.
I understand, the hint is about the fact that doing 64 bit calculations
on 32 bit are more expensive. But that was not my question.
Why does " signed_32bit or unsigned_32bit " need to be extended and
calculated in 64 bit? "or" operates on a set of bits. Afaik for the "or"
statement, there is no diff in signed/unsigned?
---------
BTW, the thin text should really be changed. It is (from what I can see
/ was told) not at all about the result. It is about the operation.
e.g in "if signed32 < unsigned32 then" there is a boolean result (Which
I do not think will be a 64 bit bool?). So saying a "64 bit result"
appears actually wrong.
Hint: Mixing signed expressions and longwords will use 64bit operations
More information about the fpc-devel
mailing list