Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-03

bool / boolean converting

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Peter J. Haas

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?

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;

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?

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)

wkr Peter.

Peter Vreman
to Peter J. Haas
you wrote 22 lines
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

Show quoted text 12 lines
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

Show quoted text 20 lines
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

Peter J. Haas
to Peter Vreman

Hi Peter,

you wrote 18 lines
> 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.

Show quoted text 5 lines
> 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

Thanks.

Show quoted text 8 lines
> 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 , now I have understand the difference.

wkr Peter.

Arturo Gonzalez Rivera
to Peter Vreman: Can't find any description what is wrong with FPC in the above text Fixed Same fix as…

"Help about help" :

Sorry for the question, and certainly "some-many" have asked for the help files, I think the answer is too simple and with not big problem, but I can't wait longer to ask...

"I would like to know if there is a special file to be installed/configured for the IDE included in ver. 2.0.0, I recently installed this version and I find "No help files installed.. where are this help files?"

I am using i386-win32 install file (21 MBytes).

Best Regards.

Saludos.

Ing. Arturo G. Rivera.
Gorsa Xalapa Eqz., Ver., Mexico.
Tel. +52+228+8123442

Tomas Hajny
to Arturo Gonzalez Rivera

Arturo Gonzalez Rivera napsal(a):

Show quoted text 12 lines
"Help about help" : Sorry for the question, and certainly "some-many" have asked for the help files, I think the answer is too simple and with not big problem, but I can't wait longer to ask... "I would like to know if there is a special file to be installed/configured for the IDE included in ver. 2.0.0, I recently installed this version and I find "No help files installed.. where are this help files?" I am using i386-win32 install file (21 MBytes).

You need to download and install a ZIP file with documentation in HTML format. PDF documentation included in the distribution package is suitable for printing and viewing (including full-text search etc.), but not very good for IDE purposes (text-mode). Even the current HTML files are not perfect within IDE - we plan to provide yet another format for our IDE with future releases.

Tomas