[fpc-devel] BOOL
Adriaan van Os
fpc at microbizz.nl
Sun Dec 14 16:19:27 CET 2014
While doing some Win32 programming I ran into a for loop that didn't work
var b: bool;
for b := False to True do ...
whereas
var b: bool;
for b := False downto True do ...
did work. The reason seems to be the internal value of False and True for BOOL, as
program testbool;
uses Windows;
var b: BOOL;
begin
b := False;
writeln
( 'Ord( BOOL) for False = ', Ord( b));
b := True;
writeln
( 'Ord( BOOL) for True = ', Ord( b))
end.
reveals 0 for False and -1 for True, where I had expected 0 for False and 1 for True. Also,
according to <http://msdn.microsoft.com/en-us/library/eke1xt9y.aspx> the same test reveals 0 and 1
respectively in Visual Studio 2013.
So, there doesn't seem to be a WIndows compatibilty reason to use -1 for True (unless maybe if
Delphi has -1 for True, but then it would apply to mode Delphi only).
Regards,
Adriaan van Os
More information about the fpc-devel
mailing list