[fpc-devel] BOOL

Mark Morgan Lloyd markMLl.fpc-devel at telemetry.co.uk
Mon Dec 15 10:07:34 CET 2014


Adriaan van Os wrote:
> Marco van de Voort wrote:
>> In our previous episode, Adriaan van Os said:
>>> reveals 0 for False and -1 for True, where I had expected 0 for False 
>>> and
>>> 1 f
>>> according to <http://msdn.microsoft.com/en-us/library/eke1xt9y.aspx> the
>>> same
>>> respectively in Visual Studio 2013.
>>
>> There is a C (99?) bool type, and a winapi (and much older) BOOL type. 
>> Two
>> different libraries, two different headers, two different cases :-)
>>
>> In old SDKs, BOOL was defined in windef.h, but can't seem to quickly find
>> that in my current 8.1 (that was seriously mangled due to the winrt
>> additions). 
> 
> WIndef.h in the v7.0 WinSDK clearly defines
> 
> #ifdef TRUE
> #undef TRUE
> #endif
> #define TRUE  1
> 
>>
>> Afaik BOOL was implemented for winapi benefit, and the boolean* types for
>> pascal booleans (0,1)

With a slight health warning in that #undef etc. applies to the C 
preprocessor which is generally loosely-coupled to the underlying 
language. There might be cases where this model doesn't apply to Pascal 
implementations, which typically have integrated handling of compiler 
directives.

I agree that zero and false are generally equivalent, except possibly in 
the case of unix shell scripts where it gets messy. It's arguably unsafe 
to ever cast true to a number or enumeration, and possibly the best 
behaviour would be to ensure that the compiler always handled  for b := 
false to not false do  and for b := not false to false do  the same.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-devel mailing list