Testing boolean expressions: ambiguity
Posted: 05 Aug 2014 12:52
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.
However: there is an anomaly now in the behaviour when testing actualy against the 'true' value:
I think this 'creepage' towards C behaviour without other adaptations is very dangerous...
The full testcode and the results (pointed to by an arrow):
Of course, for mP users which do only give the value 'true' and 'false' to boolean variables, and which do not test non boolean variables as if they were boolean, there is no danger at all. For others...
Due to this change mP has become a little less "stong typed".
However: there is an anomaly now in the behaviour when testing actualy against the 'true' value:
Code: Select all
var_ := 1;
if var_ <---- expression is true
if var_ = true <---- expression is false
The full testcode and the results (pointed to by an arrow):
Code: Select all
program TrueTest;
{ Declarations section }
var var_: boolean;
var_2: string[5];
var_3: short;
begin
{ Main program }
var_ := 1;
if var_
then var_2 := 'true' // <---- difference with below!
else var_2 := 'false';
if var_ = true
then var_2 := 'true'
else var_2 := 'false'; // <---- difference with above!
var_ := true;
if var_
then var_2 := 'true' // <---- no difference with below
else var_2 := 'false';
if var_ = true
then var_2 := 'true' // <---- no difference with above
else var_2 := 'false';
var_3 := -1;
if Var_3
then var_2 := 'true' // <----
else var_2 := 'false';
var_3 := 0;
if Var_3
then var_2 := 'true'
else var_2 := 'false'; // <----
end.
Due to this change mP has become a little less "stong typed".