Sign in Join

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

Mailing lists / fpc-devel / 2004-11

New rules for External

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Peter Vreman

- Interface declaration has External
Every implementation declaration will give an error: (03210_E_Procedure is already declared EXTERNAL)

- Interface declaration has no External
Implementation has External
- For Win32 (maybe OS/2 also?) this is allowed when the import is done from a DLL, e.g. "external dllname name 'fsdfds'" or "cdecl;external dllname"
- Otherwise it gives an error (because the assembler name becomes different from the one already set in the interface) (03211_E_Can't declare procedure as EXTERNAL)

Reply by email

Unknown author
to Peter Vreman

This is not Delphi compatible ...

Peter Vreman wrote 23 lines
- Interface declaration has External Every implementation declaration will give an error: (03210_E_Procedure is already declared EXTERNAL) - Interface declaration has no External Implementation has External - For Win32 (maybe OS/2 also?) this is allowed when the import is done from a DLL, e.g. "external dllname name 'fsdfds'" or "cdecl;external dllname" - Otherwise it gives an error (because the assembler name becomes different from the one already set in the interface) (03211_E_Can't declare procedure as EXTERNAL) _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Peter Vreman
This is not Delphi compatible ...

Ofcourse we check this before changing things like this. Delphi only accepts the next directive for importing from DLLs:

external 'dllname' name 'functionname'

FPC supports besides importing from DLLs also referencing other public accessible assembler symbols. These can come from sharedlibraries or from linked objects or even from routines in pascal that are declared public.

external name 'functionname'
external 'dllname'

If no functionname is specified the following rules are used:
- default is to use the name as written in the source
- for cdecl declared procedures the name as written in the source prepended with _ (for most targets, some don't need the _ prefix)

For referencing functions with external in your own program or exporting for referencing from other languages like C:

public
public name 'functionname'

For the functionname the same rules as with external apply (as written in source and for cdecl prepended with a _)

Reply by email

Unknown author
to Peter Vreman

But e.g.
gcc -c -o test.ow test.c
produces identifiers *without* "_"-prefix

Peter Vreman wrote 42 lines
>This is not Delphi compatible ... > > Ofcourse we check this before changing things like this. Delphi only accepts the next directive for importing from DLLs: external 'dllname' name 'functionname' FPC supports besides importing from DLLs also referencing other public accessible assembler symbols. These can come from sharedlibraries or from linked objects or even from routines in pascal that are declared public. external name 'functionname' external 'dllname' If no functionname is specified the following rules are used: - default is to use the name as written in the source - for cdecl declared procedures the name as written in the source prepended with _ (for most targets, some don't need the _ prefix) For referencing functions with external in your own program or exporting for referencing from other languages like C: public public name 'functionname' For the functionname the same rules as with external apply (as written in source and for cdecl prepended with a _) _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

Jonas Maebe
to Peter Vreman
Peter Vreman wrote 5 lines
> But e.g. > gcc -c -o test.ow test.c > produces identifiers *without* "_"-prefix That is why you also can use "external name 'namewithoutunderscore'"

That's not entirely correct. If gcc adds an underscore to the start of symbol names by default on the target we're compiling for, then FPC will also add an underscore if you use something like this:

procedure test; cdec; external name 'test';

The reason is that otherwise such declarations become unportable and require ifdef's depending on whether or not the target platform uses an underscore by default. If you don't make the routine "cdecl", then the underscore will never be added of course (but then the routine also won't follow C calling conventions).

Jonas

Reply by email