From: pdennis@hfsi.uucp (WIS Program Group )
Subject: Re: Ada Bindings & Pragma Portability
Reply-To: pdennis@hfsi.UUCP (WIS Program Group )
Organization: HFSI, McLean VA.
Date: Fri, 2 Oct 1992 14:44:01 GMT

In article <1992Sep30.160542.19027@intrepid.com> gary@intrepid.intrepid.com (Gary Funck) writes:
>Dear Ada Experts,
>
<Deleted Text>
>
>1. Linkage to C routines.  Most vendors offer a
>"pragma interface(C, routine_name);" facitility, although at one point
>in time, it seemed that Telesoft required you to say
>"pragma interface(UNIX, routine_name);". Is this still the case?
>

More recent versions of the TeleSoft compiler allow "pragma interface (C,routine_name);"
rather than the UNIX interface.

>Most vendors seem to follow the rule that "routine_name" will be forced
>to lower case (and prefixed with "_" if that's the C naming convention).
>Is this a valid assumption?
>
>Some vendors (all of the 3 above?) offer a facility for specifying
>the exteranl symbol name explicitly, using a pragma of the form:
>pragma interface_name(routine_name, "<external name>");  Is this
>generally supported?  (though, the name may have to be prefixed
>with literal defined in a "LANGUAGE" package ... see below).

Implementation dependant pragmas are just that, implementation dependant.  In the 
TeleSoft environment, "interface_name" has been replaced with "interface_information".
You have to check the documentation (particularly Appendix F of the LRM provided by
your vendor) on supported pragmas and their use.

>2. Overlay of C records.  The Ada bindings package has the requirement
>to offer programmer visibility to various records used to communicate
<More deleted text>
>
>Although representation clauses are the indisputably correct way to go,
>I'm hoping that the bindings package can depend on the underlying compiler
>to lay out a record declaration in a "natural order". Already there

<more deleted text>
>
>Is it reasonable to assume that the compiler laid the fields out in
>the order given, and used the host machine's convention for laying
>out the data? 
>
NO, this is not a reasonable assumption at all.  The only way to ensure a 
specific layout of a record type is to use a representation specification
for the given type.

>3. References to external data objects.  The bindings package needs
>to access a couple of global variables that return status codes afer
>various database operations.  The first approach used was to say
>something along these lines:
>
>    SQLCODE: INT;
>    pragma interface_name(SQLCODE, "sqlcode");
>
>This works with the Verdix compiler, but apparently is not supported
>by Alsys.  To be truthful, it didn't work on all platforms with the
>Verdix compiler; the declaration had to be augmented as follows:
>
>    SQLCODE: INT;
>    pragma interface_name(SQLCODE, LANGUAGE.PREFIX & "sqlcode");
>
>Given the problems with interfacing directly to the data value, it looks
>as if we'll need to call C functions instead, that return the status
>values.  Fortunately, the Ada programs don't modify the data values,
>otherwise the "transparency" of the function is lost (ie,
>a function of the form "set_sqlcode(value);" would be called instead
>of the more natural syntax: "sqlcode := value;).
>
>Is it generally necessary to write data access functions in C (or
>FORTRAN, etc) to offer access from an Ada program to global data values
>in the "foreign language", or is there some other "reasonably"
>portable approach?
>
Personally the only method that I have used to access external data values
is to write access functions as you suggest.  A somewhat sleazy approach would
be to declare the object globally in the package and modify it in the package
body to it appears to be updated by the library routine.  Mind you I said this
was sleazy, but it does work.
>                              - - -
<More deleted text>
>
>thanks,
>
>- Gary
>
>PS: I hope Ada 9X (or some other effort) will standardize the pragmas
>and other methods used provide interfaces between Ada and
>(commonly used) non-Ada libraries.
>-- 
>| Gary Funck  		    gary@intrepid.com  [uunet!uupsi!intrepid!gary]
>| Intrepid Technology Inc., Mountain View CA (415) 964-8135
>--

This is based on the few bindings that I have written that required an interface to C/Unix.


--Phil Dennis			pdennis@hfsi.com
  HFSI, WIS Program Group, McLean, Va. (703) 827-3564
Newsgroups: comp.lang.ada