Next: , Previous: MoveRight, Up: Reference


(Under construction.)


procedure/function_header; external name name;

procedure/function_header; attribute (name = name);


variable_declaration; external name name;

variable_declaration; attribute (name = name);


unit Name; attribute (name = name);


The name directive declares the external name of a procedure, function or variable. It can be used after external or within attribute.

This directive declares the external name of a procedure, function or variable. The external name of the routine is given explicitly as a case-sensitive constant string expression. This is useful when interfacing with libraries written in other languages.

With this extension it is possible to access all external functions, for example the X11 interface functions, and not only those written in lowercase.

name can also be applied to units and module interfaces. In this case it denotes the prefix prepended to the external name of the initializer of the unit: While it is normally called init_Modulename, it is called init_name_Modulename when name is given.

This is not of interest under normal circumstances since the initializers are called automatically. It can help avoiding conflicts when there are several units of the same name within one program. Again, this does not happen normally, but e.g., when a program uses a unit/module that has the same name as one of the units the RTS consists of: The RTS uses GPC as the name for its units to avoid conflicts.

In the future, a name directive applied to units, modules and programs (the latter is recognized syntactically already, but has no effect yet) will also affect the default external name of routines and variables which have no name directive themselves. Again, this is mostly useful for libraries etc., and will not be necessary for normal units, modules and programs.

Conforming to

name is a Borland Pascal extension. attribute and the application of name to units, modules and programs are GNU Pascal extensions.


     program NameDemo;
     { Make two variables aliases of each other by using `name'.
       This is not good style. If you must have aliases for any reason,
       `absolute' declarations may be the lesser evil ... }
       Foo: Integer; attribute (name = 'Foo_Bar');
       Bar: Integer; external name 'Foo_Bar';
     { A function from the C library }
     function PutS (Str: CString): Integer; external name 'puts';
       Result: Integer;
       Result := PutS ('Hello World!');
       WriteLn ('puts wrote ', Result, ' characters (including a newline).');
       Foo := 42;
       WriteLn ('Foo = ', Foo);
       Bar := 17;
       WriteLn ('Setting Bar to 17.');
       WriteLn ('Now, Foo = ', Foo, '!!!')

See also

Keywords, attribute, external, Importing Libraries from Other Languages.