[fpc-pascal] bool / boolean converting

Peter J. Haas fpc.ml at pjh2.de
Fri Mar 18 21:17:38 CET 2005

Hi Peter,

on 2005-03-18T17:31:53+01:00 you wrote:
>> So far I could see it in the FPC sources, BOOL is declared as
>> WINBOOL and this as longbool. In Windows general 0 mean False and
>> any value <> 0 mean True. In the Windows API TRUE is declared as 1
>> (at 16, 32 and as well as 64 bit API).
>> Additionally there exist VARIANT_TRUE (type VARIANT_BOOL = 16 bit
>> unsigned Integer), which is declared as -1.
>> I don't know why, but Borland declared True as -1 resp. $FFFFFFFF
>> for the Windows boolean types. This cause problems with few Windows
>> API function, which expect 1 as TRUE. I don't know, whether there
>> are Windows API function, which expect -1, I have worked only with
>> TP and Delphi.
>> There are any compiler options in FPC to make FPC compatibel to
>> Borland, if anybody want to do this?

> Can't find any description what is wrong with FPC in the above text

Of course, in this case Borland's declaration is wrong. However,
Delphi and FPC are not compatible in this detail. Perhaps existing
code, developed and tested under Delphi, failed with FPC. E.g. code
which use dirty type casts. A other example are header conversations,
which use the type WordBool in OLE/COM related stuff (Delphi TOleBool
= WordBool).

With a compatibility compiler option, such code could be used without
potential problems. But I expect don't to use the -Mdelphi option.

In every case this incompatibility should be documented, e.g. in the
Reference guide, chapter 3.1, Ordinal types / Boolean types.

>> I have detect this, because I get a hint 'Type size mismatch,
>> possible loss of data / range check error', if I convert Bool to
>> Boolean. ...

> Fixed


>> BTW: Is it meaningful, that the message is identical independent
>> whether the range check is on or off?
>> (type_w_smaller_possible_range_check und
>> type_h_smaller_possible_range_check)

> The code is not always wrong, therefor it is a hint. But when range
> checks are enabled it is changed to a warning because there is a
> change that it'll be triggered at runtime.

Thanks, now I have understand the difference.

wkr Peter.

More information about the fpc-pascal mailing list