Adriaan van Os wrote:
GPC accepts:
var i: integer value not 0;
but it doesn't accept:
var w: word value not 0;
not.pas:4: error: constant out of range not.pas:4: error: initial value is of wrong type
so, the workaround is:
var w: word value not word( 0);
At first sight, this looks a bit clumsy (but at second sight it may not). It gives rise to general questions about the type of constants in Pascal, e.g.
- is there a difference between $FF.. and $0FF.. ?
- is $FF.. signed or not ?
Any comments ?
Really, we already had long discussions about integers (but can we access mailing list archive while http://www.gnu-pascal.de/ is down?)
In Pascal constants are just integers (without further type restrictions). One may think that constants are really mathematical integers (but unlike Ada, in Pascal compiler is allowed to restrict range of constants which appear in intermediate expressions).
GPC has many builtin types, some of then larger then 'integer'. Currently GPC treats constants that are small enough as 'integer' and performs all intermediate calculations with limited precision. That may produce (un)expected truncation/overflow. AFAICS `not 0' is the same as `-1': the bit pattern is truncated to integer size and treated as signed number.
The problem with `not 0' IMHO is that C type bit operations really do not fit Pascal rules. One can imagine various approaches to Pascal bit operations: -- have bitsting type and conversion functions from/to integers -- have a modular types (again + conversions) -- have three (or four?) argument bit operations, the third argument would give desired precision. Additionaly signed/unsigned result could be choosen (either using extra argumment or having differently named operations) -- compute using single largest type and explicitly truncate to smaller types
In GPC we are bound by backward (and BP) compatibility, so alternate approaches are less atractive. So your workaround is probably the best what can be done.