[fpc-pascal] bool / boolean converting

Peter Vreman peter at freepascal.org
Fri Mar 18 17:31:53 CET 2005


At 20:22 17-3-2005, you wrote:
>Hi,
>
>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
>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



>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:
>
>var
>   B1: LongBool;
>   B2: Boolean;
>begin
>   B1 := True;
>   B2 := B1;
>end;

Fixed


>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:
>
>var
>   B1: LongBool;
>   B2: Boolean;
>begin
>   B1 := LongBool(-1);
>   B2 := B1;
>   ShowMessage(Format('%d %d', [Ord(B1), Ord(B2)]));
>end;
>
>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?

Same fix as above


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


Peter





More information about the fpc-pascal mailing list