A function or procedure declaration can contain modifiers. Here we list the various possibilities:
Modifiers
Free Pascal doesn't support all Turbo Pascal modifiers, but does support a number of additional modifiers. They are used mainly for assembler and reference to C object files. More on the use of modifiers can be found in Programmer's guide.
The Public keyword is used to declare a function globally in a unit. This is useful if you don't want a function to be accessible from the unit file, but you do want the function to be accessible from the object file.
as an example:
If another program or unit uses this unit, it will not be able to use the
function Second, since it isn't declared in the interface part.
However, it will be possible to access the function Second at the
assembly-language level, by using it's mangled name (Programmer's guide\).
The cdecl modifier can be used to declare a function that uses a C type calling convention. This must be used if you wish to acces functions in an object file generated by a C compiler. It allows you to use the function in your code, and at linking time, you must link the object file containing the C implementation of the function or procedure.
As an example:
When compiling this, and linking to the C-library, you will be able to call
the strlen function throughout your program. The external
directive tells the compiler that the function resides in an external
object filebrary (see ).
Remark The parameters in our declaration of the C function should match exactly the ones in the declaration in C. Since C is case sensitive, this means also that the name of the function must be exactly the same. the Free Pascal compiler will use the name exactly as it is typed in the declaration.
Popstack does the same as cdecl, namely it tells the Free Pascal compiler that a function uses the C calling convention. In difference with the cdecl modifier, it still mangles the name of the function as it would for a normal pascal function.
With popstack you could access functions by their pascal names in a library.
Sometimes you must provide a callback function for a C library, or you want
your routines to be callable from a C program. Since Free Pascal and C use
different calling schemes for functions and procedures, the compiler must be told to generate code
that can be called from a C routine. This is where the Export modifier
comes in. Contrary to the other modifiers, it must be specified separately,
as follows:
The square brackets around the modifier are not allowed in this case.
Remark: as of version 0.9.8, Free Pascal supports the Delphi cdecl modifier. This modifier works in the same way as the export modifier.
More information about these modifiers can be found in the Programmer's guide in the section on the calling mechanism and the chapter on linking.
As of version 0.9.8, Free Pascal supports the Delphi stdcall modifier. This modifier does actually nothing, since the Free Pascal compiler by default pushes parameters from right to left on the stack, which is what the modifier does under Delphi (which pushes parameters on the stack from left to right).
More information about this modifier can be found in the Programmer's guide in the section on the calling mechanism and the chapter on linking.
The Alias modifier allows you to specify a different name for a procedure or function. This is mostly useful for referring to this procedure from assembly language constructs. As an example, consider the following program:
Remark: the specified alias is inserted straight into the assembly
code, thus it is case sensitive.
The Alias modifier, combined with the Public modifier, make a powerful tool for making externally accessible object files.