[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 ...


	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;
	  b := False;
	    ( 'Ord( BOOL) for False = ', Ord( b));
	  b := True;
	    ( 'Ord( BOOL) for True  = ', Ord( b))

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).


Adriaan van Os

More information about the fpc-devel mailing list