Sign in Join

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

Mailing lists / fpc-devel / 2001-04

Delphi incompatibility again!

7 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Pavel V. Ozerski

Hello,
Again a Delphi incompatibility is found! At least with Delphi 3. Essence: the internals of longbool, wordbool and bytebool types in FPC aren't the same as in Delphi 3. That causes serious problems by porting Delphi code with typecastings like word(a_wordbool_variable), e.g. by calculating of index offsets in arrays!

A sample which demonstrates differences between FPC and Delphi 3:

{$ifdef fpc}
{$mode delphi}
{$endif}
{$apptype console}
const
 x:longbool=true;
 y:wordbool=true;
 z:bytebool=true;
 w:boolean=true;
begin
 writeln(longint(x),' ',word(y),' ',byte(z),' ',byte(w));
end.

Output:
1) sample is compiled by FPC:
1 1 1 1
2) sample is compiled by Delphi 3:
-1 65535 255 1

Cause (only essence, I did not search details in compiler source): Delphi 3 sets ALL bits in variable to binary 1 if the variable value will be true and its type is longbool, wordbool or even bytebool (unlike boolean). Unlike Delphi, FPC uses actually only one bit.

Sincerely, Pavel

Pavel V. Ozerski | Inst. of Evolutionary Physiology & Biochemistry, office +7 (812)552-6870(291)| Russian Academy of Sciences, FAX +7 (812)552-3012 | Thorez pr. 44, St.Petersburg, 194223, Russia home +7 (812)528-5576 | E-mail: |

Reply by email

Peter Vreman
Hello, Again a Delphi incompatibility is found! At least with Delphi 3. Essence: the internals

of
longbool, wordbool and bytebool

types in FPC aren't the same as in Delphi 3. That causes serious problems by porting

Delphi code with typecastings

Show quoted text 25 lines
like word(a_wordbool_variable), e.g. by calculating of index offsets in arrays! A sample which demonstrates differences between FPC and Delphi 3: {$ifdef fpc} {$mode delphi} {$endif} {$apptype console} const x:longbool=true; y:wordbool=true; z:bytebool=true; w:boolean=true; begin writeln(longint(x),' ',word(y),' ',byte(z),' ',byte(w)); end. Output: 1) sample is compiled by FPC: 1 1 1 1 2) sample is compiled by Delphi 3: -1 65535 255 1 Cause (only essence, I did not search details in compiler source): Delphi 3 sets ALL bits in variable to binary 1 if the variable value will be true and

its
type is

longbool, wordbool or even bytebool (unlike boolean). Unlike Delphi, FPC uses actually only one bit.

The value of true in a boolean is undefined. All checks for booleans are done using checks for zero or not zero.

Reply by email

Marco van de Voort
to Peter Vreman
Show quoted text 7 lines
type is > longbool, wordbool or even bytebool (unlike boolean). > Unlike Delphi, FPC uses actually only one bit. The value of true in a boolean is undefined. All checks for booleans are done using checks for zero or not zero.

No. They can also get compared to other booleans, and those types exist for C compability, and could be compared with external C vars ?

Reply by email

Jonas Maebe
to Marco van de Voort
Marco van de Voort wrote 5 lines
> The value of true in a boolean is undefined. All checks for booleans are done using checks > for zero or not zero. No. They can also get compared to other booleans, and those types exist for C compability, and could be compared with external C vars ?

C has no boolean type. And C++'s bool is just a dirty hack (implicit type casting between int and bool is perfectly possible).

Jonas

Reply by email

Pavel V. Ozerski
to Peter Vreman: of longbool, wordbool and bytebool Delphi code with typecastings its type is The value of…
The value of true in a boolean is undefined. All checks for booleans are done using checks for zero or not zero.

It is true but if we don't use tricks. Example:

const
 x:array[0..1]of longint=(1,2);
var
 y:longbool;
 s:string;
begin
 readln(s);
 y:=s'';
 writeln(x[longint(y)])
end.

This sample is very abstract, of course. It will work correctly only compiled with FPC. But if x will be defined as array[-1..0]of longint, only Delphi-compiled version will work properly.

Pavel

Pavel V. Ozerski | Inst. of Evolutionary Physiology & Biochemistry, office +7 (812)552-6870(291)| Russian Academy of Sciences, FAX +7 (812)552-3012 | Thorez pr. 44, St.Petersburg, 194223, Russia home +7 (812)528-5576 | E-mail: |

Reply by email

Marco van de Voort
to Jonas Maebe: C has no boolean type. And C++'s bool is just a dirty hack (implicit type casting between…
Show quoted text 10 lines
On Mon, 2 Apr 2001, Marco van de Voort wrote: > > The value of true in a boolean is undefined. All checks for booleans are done using checks > > for zero or not zero. > > No. They can also get compared to other booleans, and those types exist for > C compability, and could be compared with external C vars ? C has no boolean type. And C++'s bool is just a dirty hack (implicit type casting between int and bool is perfectly possible).

I know. But I thought those types were to declare C's short,-,long bool as external.

Therefore they have the same values. Why would you otherwise need those types at all?

Reply by email

Jonas Maebe
to Marco van de Voort
Marco van de Voort wrote 8 lines
> C has no boolean type. And C++'s bool is just a dirty hack (implicit type > casting between int and bool is perfectly possible). I know. But I thought those types were to declare C's short,-,long bool as external. Therefore they have the same values. Why would you otherwise need those types at all?

I don't know, but my g++ has never heard of byte-, word- or longbool at least (or bool8/bool16/bool32). And the normal bool does use 1 for true and 0 for false.

Jonas

Reply by email