[fpc-pascal] bool / boolean converting

Peter J. Haas fpc.ml at pjh2.de
Thu Mar 17 20:22:21 CET 2005


first, sorry my bad english. I have post this and the next two
questions already in community (german language forum).

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

There are any compiler options in FPC to make FPC compatibel to
Borland, if anybody want to do this?

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.

Simple example:

  B1: LongBool;
  B2: Boolean;
  B1 := True;
  B2 := B1;

I have make some tests, apparently FPC use a automatic type convert,
similar to Delphi, which make sure, that the Boolean value is in a
valid range:

  B1: LongBool;
  B2: Boolean;
  B1 := LongBool(-1);
  B2 := B1;
  ShowMessage(Format('%d %d', [Ord(B1), Ord(B2)]));

output: '-1 1'.

If there is a type convert (instead of a type cast), the hint is
meaningless. The same hint appear, if I use a LongBool variable with a
Boolean parameter in a function.

Is this a bug?

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

wkr Peter.

More information about the fpc-pascal mailing list