Couperin wrote:
I get false results when I use comparison operators with Packed subrange types. For example if X is of a packed user defined type, and is equal to 64, then "X > 63" yields false !
Indeed. I checked the assembler output, and it seems that there is no comparison done, as if the compiler had any reason to assume the comparison would always be false (like, say, X > 125 which can't be true if X is of type 0 .. 125).
There is another bug. If I define : ---------- Const XValueMax :Byte = 125; Type T_XValue = Packed 0..XValueMax; ---------- or ---------- Const XValueMax = 125; Type T_XValue = 0..XValueMax; ---------- then the results are good but "T_XValue" is now the 32 bits Integer type !
In the second case, that's ok, since you didn't declare it packed, and GPC will use the more efficient 32 bit type then. In the first case, it's surprising indeed.
Even stranger, GPC allows:
var XValueMax :Byte = 125; Type T_XValue = Packed 0..XValueMax;
which it shouldn't, I think. When this is fixed, probably also the typed const won't work anymore (because typed consts are handled mostly like variables for compatibility to a stupid BP misfeature), but I think it's ok. It should work with a real constant.
I suppose it is a known bug ["There are some bugs with mathematical functions."
No, it's not that one.
(more details in the bugs list would be helpful)]
Yes, that's one of the (few, I hope) entries in the list which are not very detailed. It refers to the Paranoia test which can be found somewhere on the Net, but AFAIR deals with some more or less strange cases of real number operations.
and maybe it's related to the following one : "Files of integer subranges that would fit in a byte do not; instead they are handled as files of integer."
No, it's not that one either. That's about files only. Your bug is new to us, thanks for the report (couper[1-3].pas).
Another try with a slight difference in the program (with no packed type):
Type T_XValue = 0..125; Var X : T_XValue;
It's OK with X = 64 but now :
X ? 4000000000 X = 4000000000
Yes, range checking is missing. That, at least, is a known bug...
The thing I don't understand is the output : X = 4000000000 X > 63 : False but it doesn't really matter : the input was wrong, since it was out of range [0..125].
It is strange. The difference seems to be due to the different handling of comparisons (in direct code) and output (in the Run Time System). But anyway, once the out-of-range value has entered into the variable, anything else is undefined.
But about the packed type, I found another problem. I can't compile this little program :
Program Bug05; Const XValMax : Byte = 125; Type T_XVal = Packed 0..XValMax; Var X : T_XVal = 64; Begin End.
Here is the output :
Reading specs from c:/djgpp/lib/gcc-lib/djgpp/2.952/specs gpc version 20000727, based on 2.95.2 19991024 (release) [...] Bug05.pas:8: constant out of range
Works on my system. But as said above, using a typed constant in a type declaration is not recommended (and may be disallowed in a future version). It works with a plain constant, doesn't it?
Frank