[fpc-devel] Do bitwise operation (1 or 2) acre about the sign ? (Giving sign related hints on compilation)

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Jan 14 17:39:30 CET 2013


On 14 Jan 2013, at 17:03, Martin wrote:

> On 14/01/2013 15:52, Jonas Maebe wrote:
>> 
>> On 14 Jan 2013, at 16:44, Martin wrote:
>> 
>>> This is casting a "set of bits" (neither signed, nor unsigned - a set is not a number at all) into a number. This only needs to have a definition, if it should cast to signed or unsigned type.
>> 
>> It has to be signed, because otherwise any negative number in the operation would trigger a range check error when it gets converted to a (larger) unsigned type. The nature of the operation that is used afterwards is irrelevant, range checking always operates in exactly the same way when performing a type conversion from one type to another. This is required to have predictable behaviour in a programming language.
> 
> not sure if I follow. If "or" performs on a "set of bits" (rather than a number)

It doesn't operate on a set. The left and right operands are whole numbers, and hence the operator works on whole numbers and returns a whole number. In Pascal, sets and whole numbers are completely distinct types with different operators. There is no magic type conversion from integer to a set and back just because you use the "or" operator.


Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20130114/cc98a3de/attachment.html>


More information about the fpc-devel mailing list