[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 9.17 asmname

### Synopsis

procedure/function header; asmname name;

or

variable declaration; asmname name;

### Description

The ``asmname'` directive declares the external name of a procedure, function or variable. The external name of the routine is given explicitly as a case-sensitive string constant. 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.

The idea to use ``external'` for this purpose (to avoid name space pollution) conflicts with another Borland extension not yet implemented: In Borland Pascal, the declaration

    procedure Foo; external 'MyLib';

means that the procedure Foo should be imported by name (``Foo'`) from a dynamic link library ``mylib.dll'`.

``asmname'` 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_asmname_Modulename'` when ``asmname'` 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 ``asmname'` for its units to avoid conflicts.

In the future, an ``asmname'` declaration 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 ``asmname'` declaration themselves. Again, this is mostly useful for libraries etc., and will not be necessary for normal units, modules and programs.

### Conforming to

``asmname'` is a GNU Pascal extension.

### Example

    program AsmnameDemo;

    { Make two variables aliases of each other by using `asmname'.
      This is not good style. If you must have aliases for any reason,
      `absolute' declaration may be the lesser evil ... }
    var
      Foo: Integer; asmname 'Foo_Bar';
      Bar: Integer; asmname 'Foo_Bar';

    { A function from the C library }
    function PutS (Str: CString): Integer; asmname 'puts'; external;

    var
      Result: Integer;
    begin
      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, '!!!')
    end.

### See also

section 9.35 C, section 9.42 c_language, section 9.84 external, section 8.11.1 Importing Libraries from Other Languages.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Frank Heckenbach on May, 10 2002 using texi2html