Node:Exporting GPC Libraries to Other Languages, Previous:Importing Libraries from Other Languages, Up:Other Languages
The .o
files produced by GPC are in the same format as those of all
other GNU compilers, so there is no problem in writing libraries for other
languages in Pascal. To use them, you will need to write kind of
interface - a header file in C. However there are some things to take
into account, especially if your Pascal unit exports objects:
procedure FooBAR
must be imported as
extern void Foobar()
from C.
attribute
:
procedure FooBAR; attribute (name = 'FooBAR'); begin WriteLn ('FooBAR') end;
This one can be imported from C with extern void FooBar()
.
vmt
field
which contains a pointer to the "virtual method table". This table is
another record of the following structure:
type VMT = record ObjectSize: PtrInt; { Size of object in bytes } NegObjectSize: PtrInt; { Negated size } Methods: array [1 .. n] of procedure; { Pointers to the virtual methods. The entries are of the repective procedure or function types. } end;
You can call a virtual method of an object from C if you explicitly
declare this struct
and explicitly dereference the Fun
array. The VMT of an object FooBAR
is an external (in C
sense) variable vmt_Foobar
internally.
Myobject_Mymethod
(with exactly
two capital letters) internally.
main
program an internal name different from
main
, call GPC with the command-line option
--gpc-main="GPCmain"
(see the previous subsection).