Dany wrote:Hi, apparently also in mP (v6.4.0) values which differ from zero are seen as 'true', while in earlier versions only the value '255' was seen as 'true'. I do not know in which version exact things changed.
I'm afraid that it never was that simple and there were always problems with boolean expressions but you're right that there was a change - and quite some time ago.
Due to this change mP has become a little less "stong typed".
You well know that there's actually no boolean type in mP (and never was). When one declares a boolean variable, it's in fact of byte type. One wouldn't be able to assign value different than TRUE or FALSE to true boolean variable or constant. And then it wouldn't matter how compiler differentiates between TRUE and FALSE, would it? In fact it would also not matter how TRUE and FALSE are defined internally. Note that Pascal definition only states that TRUE and FALSE should be of ordinal type with TRUE following FALSE and that numbers of the truth values denoted by FALSE and TRUE should be the integer values 0 and 1 respectively. (Neither is true in present mP implementation.)
mE does realize that this is a problem and there are appropriate notes in Help - for example, the 'if' conditional description contains a note
The expression must convert to a boolean type; otherwise, the condition is ill-formed.
In other words, expression in 'if' statement has to evaluate to TRUE or FALSE. If it doesn't then the behaviour of 'if' statement is unpredictable (and always was).
As I mentioned, boolean expressions were always a problem in mP (that's why I introduced a bool function in my replacement of System library) and introduction of bit logic (which is not part of Pascal) only increased the number of traps one may fall into if one's not careful.
With boolean variables/constants one has to be sure they are never assigned values other than TRUE or FALSE. One should also never mix bit logic with boolean logic in expressions. This does not mean one cannot use bit variables in boolean expressions - for example,
bit_var=1 produces boolean result and may be part of boolean expression. But
not bit_var may not lead to boolean value. Once in a while people fall into similar trap with TestBit function forgetting that it produces 0 and 1.
The above rambling has a purpose - in opposition to your reservations, Dany, testing only bit 0 of boolean value or expression result (which would seemingly deepen the C-likeness) would be a remedy to some of present problems. First, it would remove complications introduced with bit logic, second, there never would be cases of
not FALSE<>TRUE. Furthermore, though it's not a necessary condition, Pascal definition could be easily followed if TRUE and FALSE were defined as 1 & 0. (It would not introduce problems with backward compatibility - at least for code that used the TRUE and FALSE keywords, not direct internal values, which is a bad practice, anyway.)