Waldek Hebisch wrote:
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?)
Unfortunately not.
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).
Yes -- so the answers to the questions above are clearly `$FF = $0FF' (BP agrees), and `$FF.. > 0' (it can be stored in a signed or unsigned type, of course, if range permits, but it should never represent a negative value).
The problem with `not 0' IMHO is that C type bit operations really do not fit Pascal rules.
Indeed. While `and' and `or' can be defined mathematically in an abstract sense, independent of type sizes (even for negative numbers, if you assume two's complement -- other systems could still emulate it to provide the same semantics), `not' is problematic. As long as it's used in the form `a and not b', which is a common case, it's unique, but in general it's not.
Interestingly, though, `not' is unique on signed types (again, if assuming two's completement), where `not a' is equivalent to `-1 - a'. So perhaps we should declare this our official definition of integer `not' (i.e., adjust GPC where it does not bevahve like this)? BTW, BP seems to agree as well, since `not Word (0)' gives -1 there.
This would imply that Adriaan's workaround `word value not word (0)' would not work anymore. Of course there are other ways to get this value, depending on what's the real intention behind it, such as `High (Word)' (if the maximum value of a variable is meant, this is the recommended form, anyway, since it's independent of any representation issues) or just writing out the number, possibly in hex, if the actual numeric value is meant.
Frank