[fpc-devel] Dangerous optimization in CASE..OF
    Martok 
    listbox at martoks-place.de
       
    Sun Jul  2 19:51:02 CEST 2017
    
    
  
Booleans are not enums in Delphi (not even ordinals), but their own little
thing. "if boolean_expr" is always a jz/jnz, no matter what. They are defined as
0=FALSE and "everything else"=TRUE
However:
var
  b : boolean;
begin
  b:=boolean(3);
  if b = True then
    writeln(true)
  else if b = False then
    writeln(false)
  else
    writeln(ord(b));
end.
That writes 3, which is why your should never compare on the boolean lexicals.
Some Winapi functions returning longbool rely on that.
Wait, that was a trick question, wasn't it?
    
    
More information about the fpc-devel
mailing list