Bart van den Broek wrote:
If I (as an inactive observer) may comment / make a suggestion; when a constant of ByteBoole, WordBoole or LongBoole is evaluated, presumably at compile time, convert it to a value of type Boolean. As a consequence: type VeryTrue = ByteBool (10) .. ByteBool (42); means type VeryTrue = True..True; Also, in the test program fjf1102, (Ord (a) = 1) and (Ord (b) = 1) and
(Ord
(c) = 1) holds, and more specifically Ord( ByteBool(42) ) = 1.
Interesting idea, but if done only for constants (as I understand your suggestion), it would also lead to strange effects:
program foo;
var n: Integer = 42;
begin WriteLn (ByteBool (n) = ByteBool (42)) { => False } end.
Since the Borland Delphi 3 Object Pascal Language Guide mentions: "....Whenever a ByteBool, WordBool or LongBool value is used in a context where a Boolean value is expected, the compiler will automatically generate code that converts any nonzero value to the value True." If i interpret the expression ByteBool(n) = ByteBool(42) as "a context where a Boolean value is expected" then it is equivalent to (ByteBool(n) <> 0) = (ByteBool(42) <> 0), or (ByteBool(n) <> 0) = True, and foo would print True.
I don't think so (BTW, what does Delphi do?). The context here is `=' Since ByteBool is an ordinal type, and `=' allows the same ordinal type (among others) on both sides, ByteBool is valid. I.e., it's a context where Boolean is allowed, but not required. Contexts that require Boolean include the conditions in if, while, until, or assignments to Boolean variables, or Boolean value parameters.
Besides, it probably wouldn't be 100% Delphi compatible, as Delphi documentation (as quoted by Adriaan) states that Ord of "True" of such types can be any value <> 0.
Well, 1 is such a value <> 0, so how do u think it is incompatible?
OK, but if it were always 1, then they'd probably say so, and not write:
: Boolean ByteBool, WordBool, LongBool : Ord( True) = 1 Ord( True) = any non-zero value
I dont have Delphi available right now, but i vaguely remember Delphi does the following: ByteBool(True) = $FF WordBool(True) = $FFFF LongBool(True) = $FFFFFF If so (will check later) then this means my suggestion is different and maybe incompatible.
I don't either, but someone who does might want to check this (and the behaviour of my program above under Delphi). If really ByteBool(True) = $FF (I assume you mean Ord (ByteBool (True)) = $FF, or can you compare ByteBool and integers in Delphi?) that would complicate things, as normally (in BP and GPC) value type casts preserve ordinal values ...
Frank