Sign in Join

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

Mailing lists / fpc-pascal / 2010-10

declaration of functions

12 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Uffe Kousgaard

While trying to make delphi code compatible with FPC, I have hit this issue:

Delphi allows:

interface
function somefunction(a: integer): integer;
implementation
function somefunction;
begin
  result:= a*2;
end;

FPC requires the full declaration to be repeated. Can this be avoided somehow? I have many functions/procedures without full declaration in the implementation part.

TIA
Uffe Kousgaard

Reply by email

Sven Barth
to Uffe Kousgaard
Uffe Kousgaard wrote 17 lines
While trying to make delphi code compatible with FPC, I have hit this issue: Delphi allows: interface function somefunction(a: integer): integer; implementation function somefunction; begin result:= a*2; end; FPC requires the full declaration to be repeated. Can this be avoided somehow? I have many functions/procedures without full declaration in the implementation part.

Add

{$mode delphi}

at the top of your unit, then this "Delhpi compatible" syntax will be enabled. The two default FPC modes (fpc and objfpc) are more strict than the Delphi one.

Regards,
Sven

Reply by email

Jonas Maebe
to Uffe Kousgaard: While trying to make delphi code compatible with FPC, I have hit this issue: Delphi…
Uffe Kousgaard wrote 17 lines
While trying to make delphi code compatible with FPC, I have hit this issue: Delphi allows: interface function somefunction(a: integer): integer; implementation function somefunction; begin result:= a*2; end; FPC requires the full declaration to be repeated. Can this be avoided somehow? I have many functions/procedures without full declaration in the implementation part.

Add {$mode delphi} at the top of your units, or use the command line parameter -Mdelphi

Jonas

Reply by email

Michael Van Canneyt
to Uffe Kousgaard: While trying to make delphi code compatible with FPC, I have hit this issue: Delphi…
Uffe Kousgaard wrote 16 lines
While trying to make delphi code compatible with FPC, I have hit this issue: Delphi allows: interface function somefunction(a: integer): integer; implementation function somefunction; begin result:= a*2; end; FPC requires the full declaration to be repeated. Can this be avoided somehow? I have many functions/procedures without full declaration in the implementation part.
Switch on delphi mode:
{$mode delphi}

And then it should work.

FPC is more fussy about it, because unlike delphi, it doesn't require you to specify 'overload' for overloaded functions. The downside of this is that you must repeat the full declaration in the implementation section. (for obvious reasons)

Michael.

Reply by email

Jonas Maebe
to Sven Barth: Add {$mode delphi} at the top of your unit, then this "Delhpi compatible" syntax will be…
Sven Barth wrote 17 lines
Am 14.10.2010 14:50, schrieb Uffe Kousgaard: > interface > function somefunction(a: integer): integer; > > implementation > function somefunction; > begin > result:= a*2; > end; Add {$mode delphi} at the top of your unit, then this "Delhpi compatible" syntax will be enabled. The two default FPC modes (fpc and objfpc) are more strict than the Delphi one.

As an aside, this has nothing to do with strictness. The reason is that FPC and ObjFPC mode allow function overloading without the "overload" keyword. So the compiler sees the above as two overloaded functions (one public, one private) as opposed to the interface and implementation declaration of the same function.

Jonas

Reply by email

Sven Barth
to Jonas Maebe
Jonas Maebe wrote 26 lines
On 15 Oct 2010, at 11:07, Sven Barth wrote: > Am 14.10.2010 14:50, schrieb Uffe Kousgaard: >> interface >> function somefunction(a: integer): integer; >> >> implementation >> function somefunction; >> begin >> result:= a*2; >> end; > > Add > > {$mode delphi} > > at the top of your unit, then this "Delhpi compatible" syntax will be > enabled. The two default FPC modes (fpc and objfpc) are more strict > than the Delphi one. As an aside, this has nothing to do with strictness. The reason is that FPC and ObjFPC mode allow function overloading without the "overload" keyword. So the compiler sees the above as two overloaded functions (one public, one private) as opposed to the interface and implementation declaration of the same function.

Do you have to destroy my dream? :P

But you can see it as an indirect strictness. Because FPC sees a declaration with and one without parameters as two functions you can't omit the parameter declaration.

Btw: If I remember correctly, I need to repeat calling conventions as well in the FPC modes... so does the compiler treat to similar functions with two different calling conventions as overloaded?

E.g.

procedure Foo(Bar: Integer); stdcall;
procedure Foo(Bar: Integer); cdecl;

Is this possible?

If so: what's the use of this? I can't differentiate the procedures by calling convention when I call them...
If it is not so: why do I need to repeat the calling convention then (only if I remembered this correctly, of course)?

Regards,
Sven

Reply by email

Michael Van Canneyt
to Jonas Maebe: As an aside, this has nothing to do with strictness. The reason is that FPC and ObjFPC…
Jonas Maebe wrote 26 lines
On 15 Oct 2010, at 11:07, Sven Barth wrote: > Am 14.10.2010 14:50, schrieb Uffe Kousgaard: >> interface >> function somefunction(a: integer): integer; >> >> implementation >> function somefunction; >> begin >> result:= a*2; >> end; > > Add > > {$mode delphi} > > at the top of your unit, then this "Delhpi compatible" syntax will be > enabled. The two default FPC modes (fpc and objfpc) are more strict than > the Delphi one. As an aside, this has nothing to do with strictness. The reason is that FPC and ObjFPC mode allow function overloading without the "overload" keyword. So the compiler sees the above as two overloaded functions (one public, one private) as opposed to the interface and implementation declaration of the same function.

Isn't it amazing ? 2 core FPC developers give the same explanation :-)

Michael.

Reply by email

Uffe Kousgaard
to Uffe Kousgaard: While trying to make delphi code compatible with FPC, I have hit this issue: Delphi…

Thanks to all. I just found the link on
http://www.freepascal.org/maillist.var to GMANE, so I can follow the list in my newsreader.

But the correct syntax for the link to work is news:// , not nntp://. At least with outlook express.

Since I'm compiling for WinCE at the moment, would anybody know if there is something wrong with the emulator from MS?
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=A120E012-CA31-4BE9-A3BF-B9BF4F64CE72

It keeps stopping installation halfway through with message "was interrupted". No further errors.

Compiling with freepascal actually pointed out a few details which the delphi compiler didn't care about. Got code cleaned up a bit that way :-)

Regards
Uffe Kousgaard

"Uffe Kousgaard" wrote in
message

Show quoted text 26 lines
While trying to make delphi code compatible with FPC, I have hit this issue: Delphi allows: interface function somefunction(a: integer): integer; implementation function somefunction; begin result:= a*2; end; FPC requires the full declaration to be repeated. Can this be avoided somehow? I have many functions/procedures without full declaration in the implementation part. TIA Uffe Kousgaard _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Sven Barth
to Michael Van Canneyt: Isn't it amazing ? 2 core FPC developers give the same explanation :-) Michael.
Michael Van Canneyt wrote 32 lines
On Fri, 15 Oct 2010, Jonas Maebe wrote: > > On 15 Oct 2010, at 11:07, Sven Barth wrote: > >> Am 14.10.2010 14:50, schrieb Uffe Kousgaard: >>> interface >>> function somefunction(a: integer): integer; >>> >>> implementation >>> function somefunction; >>> begin >>> result:= a*2; >>> end; >> >> Add >> >> {$mode delphi} >> >> at the top of your unit, then this "Delhpi compatible" syntax will be >> enabled. The two default FPC modes (fpc and objfpc) are more strict >> than the Delphi one. > > As an aside, this has nothing to do with strictness. The reason is > that FPC and ObjFPC mode allow function overloading without the > "overload" keyword. So the compiler sees the above as two overloaded > functions (one public, one private) as opposed to the interface and > implementation declaration of the same function. Isn't it amazing ? 2 core FPC developers give the same explanation :-)

Should I be worried that you find this amazing? O.o

Regards,
Sven

Reply by email

Felipe Monteiro de Carvalho
to Uffe Kousgaard: Thanks to all. I just found the link on http://www.freepascal.org/maillist.var to GMANE,…
Uffe Kousgaard wrote 6 lines
Since I'm compiling for WinCE at the moment, would anybody know if there is something wrong with the emulator from MS? http://www.microsoft.com/downloads/en/details.aspx?FamilyID=A120E012-CA31-4BE9-A3BF-B9BF4F64CE72 It keeps stopping installation halfway through with message "was interrupted". No further errors.

Use the instructions here:

http://wiki.lazarus.freepascal.org/Windows_CE_Interface#Windows_Mobile_5.0_Emulator

They always worked perfectly for me.

Felipe Monteiro de Carvalho

Reply by email

Jürgen Hestermann
to Sven Barth: Add {$mode delphi} at the top of your unit, then this "Delhpi compatible" syntax will be…
Show quoted text 5 lines
> FPC requires the full declaration to be repeated. Can this be avoided > somehow? I have many functions/procedures without full declaration in > the implementation part. Add {$mode delphi}

I would not suggest to use {$mode delphi}
but {$ModeSwitch REPEATFORWARD+} instead.
This only changes one behaviour while {$mode delphi} changes a lot (possibly unwanted) other things too.

Reply by email

Jonas Maebe
to Jürgen Hestermann
Jürgen Hestermann wrote 11 lines
Sven Barth schrieb: >> FPC requires the full declaration to be repeated. Can this be avoided >> somehow? I have many functions/procedures without full declaration in >> the implementation part. > Add > {$mode delphi} I would not suggest to use {$mode delphi} but {$ModeSwitch REPEATFORWARD+} instead. This only changes one behaviour while {$mode delphi} changes a lot (possibly unwanted) other things too.

Since he's porting Delphi code, {$mode delphi} is definitely the way to go. Just enabling REPEATFORWARD will e.g. keep integer=smallint, which undoubtedly will cause further problems.

Jonas

Reply by email