#pragma interface(C,"foo") 
Author Message
 #pragma interface(C,"foo")

Could someone assist a beleagured C programmer with this Ada stuff??

For several days I chased through linking errors trying to figure out why my
compiled Ada source would result in a slew of unresolved linker errors.  After
examining the error list numerous times, I realized that the Verdix (v6.0.3) Ada
compiler was failing to prepend an underscore to all of my C interface pragma
statements; i.e. pragma INTERFACE (C,"foo") was resulting in the "foo" (not
"_foo") symbol being placed in the object file.  I changed all my interface
statements, recompiled, linked, and everything worked fine....

If the pragma INTERFACE (C,"foo") statement indicates we want to link to an
external C symbol, why didn't the VADS compiler generate a C compatible symbol
reference?  Is there some compiler switch or other pragma I need to throw so
this will happen?

            "... big dogs landing on my face ..."
                                   -- Robin Williams, 'Good Morning, Vietnam'

Applied Research        Phone:    (512) 835-3621
  Laboratories          Fedex:    10000 Burnet Road, Austin, Texas 78758-4423
University of Texas     Postal:   P.O. Box 8029, Austin, Texas 78713-8029

Sat, 26 Mar 1994 02:34:16 GMT  
 #pragma interface(C,"foo")
The bottom line is that you should use pragma INTERFACE_NAME to
specify the linker name for your routine:
        pragma INTERFACE (C, "foo");
        pragma INTERFACE_NAME ("foo", "_foo");

The ISO WG9 Uniformity Rapporteur Group has developed a recommendation
on this.  The idea is that "conforming compilers" will adopt this
recommendation, and your resulting code will be much more portable,
because every compiler will handle this issue the same way.  

Here's the text of the Uniformity Issue:

UI-0036                 pragma INTERFACE_NAME                   0036/3

Editor:  David Emery
Status:  Agreed by URG - Submitted to ISO WG9
Section:  RM 13.9
AI References:  AI-00317

ISSUE: Pragma INTERFACE is by its nature implementation dependent.
However it may be possible to specify some common subset that should
normally be implemented. In addition, most implementations must extend
this pragma to specify link names. Should the form and use of such
extensions be specified?

RECOMMENDATION: Implementations should support a pragma
INTERFACE_NAME.  This pragma shall take two parameters, an Ada
identifier and a string.  Permissible values for the Ada identifier
include a subprogram_name used in a previous pragma INTERFACE.  The
interpretation of the string is implementation-dependent, but the
intent is that the string shall denote a name used by the
linker/binder to identify and resolve a reference to the subprogram
named in a preceding pragma INTERFACE.

Other uses of this pragma (such as defining an Ada object/variable as
an externally visible object) are not defined by this UI.  Nor does
this UI define the meaning of pragma INTERFACE_NAME when the Ada
identifier is a subprogram_name which is not used in a preceding

DISCUSSION: Although the full implementation of pragma INTERFACE is
bound to be implementation dependent, in practice programs which use
pragma INTERFACE are more portable than one might expect on first

For example, consider the following:

           function AND_INT (A, B : INTEGER) return INTEGER;
           pragma INTERFACE (C, AND_INT);

and the corresponding C function:

           int AND_INT (a,b)
           int a,b;
              return a & b;

It seems likely that this will work with no changes on many
implementations.  Probably the only changes that might be required are
the language name (one might encounter something like VAX_C or
MICROSOFT_C in some environments), and the integer types used in the C
program (if int in C does not correspond to INTEGER in Ada).

Should an attempt be made to specify a subset of pragma INTERFACE
declarations which are expected to be portable across implementations
where possible?

Another issue to consider is the form of the extension, provided in
most implementations, to specify a link name different from the
procedure name.  For example, given that case is important in C and
that lower case is the convention for procedure names in C, one might
see something like:

        function AND_INT (A, B : INTEGER) return INTEGER;
        pragma INTERFACE (C, AND_INT);
        pragma INTERFACE_NAME (AND_INT, "and_int");

Another case of the need for such a feature arises if the name of the
interfaced function does not meet the syntax for identifier names in
Ada.  On many Unix systems, the name of a C function recognized by the
linker has an underscore prepended to it, so the resulting code would

        pragma INTERFACE_NAME (AND_INT, "_and_int");

Another example occurs when the external name of the subprogram is an
Ada reserved word, such as the C function access in Unix.

The example given above specifies one possible syntax, as implemented
in one particular existing compiler.  Other existing compilers use
different syntax to achieve essentially the same effect. Should the
form of this extension be specified?  The most natural extension is to
add an optional third argument to pragma INTERFACE. Is this approach

One compiler that originally supported an optional third parameter to
pragma INTERFACE was forced to remove this feature during validation.
However, other compilers have since passed validation with an optional
third parameter to the pragma.


  Compiler(host)                Facility for specifying linker name
  Verdix(Sun)                   pragma  INTERFACE_NAME
  Alsys(Sun)                    pragma  INTERFACE_NAME
  Meridian(Mac)                 third parameter to pragma  INTERFACE
  DEC(VMS)                      set of three pragmas:  
                                  IMPORT_FUNCTION, IMPORT_PROCEDURE,
  Telesoft(Sun)                 pragma  LINKNAME
  DDC (80x86                    INTERFACE_SPELLING
       cross compiler)

Mon, 28 Mar 1994 01:34:43 GMT  
 #pragma interface(C,"foo")

>I realized that the Verdix (v6.0.3) Ada
>compiler was failing to prepend an underscore to all of my C interface pragma
>statements; i.e. pragma INTERFACE (C,"foo") was resulting in the "foo" (not
>"_foo") symbol being placed in the object file.

when using Verdix's Ada compiler, the best bet is to
"with" the package language that defines link name
prefixes for languages like C and fortran (this package
is supplied by Verdix)  and then use the non standard
pragma interface_name to declare the link name.

with language;
pragma interface (C, bozo);
pragma interface_name (bozo, language.c_prefix & "bozo");

this will at least be portable among Verdix compilers

Software Productivity Consortium  2214 Rock Hill Rd, Herndon VA 22070

Sun, 27 Mar 1994 23:54:49 GMT  
 [ 3 post ] 

 Relevant Pages 

1. A use for "foo = foo()"

2. $foo == "" or [llength $foo] == 0

3. "import foo" and "from foo import bar"

4. "foo"

5. Dpulicating "class Foo:" in C

6. print "foo", without a space

7. "exception in foo.__del__() ignored" strangeness

8. Pragma Exports to "C" Structure Elements

9. next "big" language?--New Pragmas

10. "Formal CS"

11. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

12. utility to replace "end" with "end subroutine foo"


Powered by phpBB® Forum Software