Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The "local" directive in Delphi

Tags:

I was sitting around debugging some code and I stumbled across this line in SysUtils.pas:

procedure ConvertError(ResString: PResStringRec); local;

What does the local keyword do exactly? It seems the ConvertError function is not declared in the interface section of the file, is this just a clarification that the function is indeed local, or is there a practical benefit to using this directive beyond that?

like image 828
kling Avatar asked Apr 02 '13 12:04

kling


People also ask

Which are compiler directives?

A compiler directive is a statement that causes the compiler to take a specific action during compilation. Conditional compilation provides a way of including or omitting selected lines of source code depending on the values of literals specified by the DEFINE directive.

What are directives in VB net?

The VB.Net compiler directives give instructions to the compiler to preprocess the information before actual compilation starts. All these directives begin with #, and only white-space characters may appear before a directive on a line. These directives are not statements.


1 Answers

It dates back to the Linux compiler, Kylix. Here's what I can see in my Delphi 6 language guide, page 9-4:

The directive local, which marks routines as unavailable for export, is platform-specific and has no effect in Windows programming.

On Linux, the local directive provides a slight performance optimization for routines that are compiled into a library, but are not exported. The directive can be specified for standalone procedures and functions, but not for methods. A routine declared with local—for example.

function Contraband(I: Integer): Integer; local;

—does not refresh the EBX register and hence

  • cannot be exported from a library.
  • cannot be declared in the interface section of a unit.
  • cannot have its address take or be assigned to a procedural-type variable.
  • if it is a pure assembler routine, cannot be called from a another unit unless the caller sets up EBX.
like image 140
David Heffernan Avatar answered Sep 18 '22 18:09

David Heffernan