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

Marco van de Voort marcov at stack.nl
Mon Jan 14 17:32:46 CET 2013


In our previous episode, Martin said:
> not sure if I follow. If "or" performs on a "set of bits" (rather than a 
> number), and a set (not being a number) is neither signed or unsigned, 
> then before the "OR" both operands (independent of being signed or not) 
> will be cast to a set. The result is a set. The set can be converted to 
> either signed or unsigned. The set has no range checking.
> 
>    result := bit_set32(a) or bit_set32(b)
> 
> If result has also 32 (or more) bits, then no range check error can 
> occur. In the set, the high-bit has no meaning. It is neither part of 
> the (unsigned positive) numer, nor is it sign indicator. This meaning is 
> only applied by casting it to a numeric type.
> 
> Same as
> var i: set of (b0, b1, b2 .... b31);
> signed := integer(i);
> unsigned := cardinal(i);

You are redoing what Wirth did 32 years ago. Pascal's successor, Modula2
does exactly that. (though bitwise operations on integers was a very common
extension)




More information about the fpc-devel mailing list