comp.lang.ada
 help / color / mirror / Atom feed
* Re: C interface - Apex/Verdix
  1997-05-29  0:00 C interface - Apex/Verdix Paul Van Bellinghen
@ 1997-05-29  0:00 ` Christopher Green
  1997-05-30  0:00   ` Mark Bennison
  1997-06-04  0:00   ` Gary Brumfield
  0 siblings, 2 replies; 6+ messages in thread
From: Christopher Green @ 1997-05-29  0:00 UTC (permalink / raw)



In article <338ce5d2.87925678@news.mhv.net>,
Paul Van Bellinghen <pvanbell@mhv.net> wrote:
>Has anyone ever intefaced a C object module with an (Ada83) Ada
>program in the Rational Apex or Verdix VadsCross environment? I am
>planning to just include the object module in the compilation view and
>use the  Pragma Interface (C, c-function-name). Will this work?

You may also need pragma Interface_Name (c-function-name, "actual-name");
this will account for situations where VADS name-mangling doesn't yield
the correct name for the C function.

Apex for Ada 83 has pragma Import_Function and pragma Import_Procedure,
which combine the effects of these two pragmas, but they are not portable.
Apex for Ada 95 has pragma Import, which is portable.

For example, you could write a binding to the libc function getenv()
as follows:

    function Getenv (Name : in System.Address) return System.Address;
    pragma Interface (C, Getenv);
    pragma Interface_Name (Getenv, Language.C_Subp_Prefix & "getenv");

(Language is a predefined package on VADS that provides the correct
prefixes for external names; for example, on SunOS 4 hosts,
Language.C_Subp_Prefix is the string "_".)

Also, you will need to make sure that the Ada types you use are
equivalent to the C types that the C object module is expecting.
If you are passing pointers to composite types, you will probably
need to write rep specs in Ada to get the compiler to lay out
the types correctly.

This is easier in Ada 95, where you have the package Interfaces.C.
If you have to do a lot of this, it may be worthwhile considering
a move to Ada 95.

Chris Green                                  Email cgreen@atc.com
Advanced Technology Center                   Phone (714) 583-9119
22982 Mill Creek Drive                                   ext. 220
Laguna Hills, CA 92653                       Fax   (714) 583-9213




^ permalink raw reply	[flat|nested] 6+ messages in thread

* C interface - Apex/Verdix
@ 1997-05-29  0:00 Paul Van Bellinghen
  1997-05-29  0:00 ` Christopher Green
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Van Bellinghen @ 1997-05-29  0:00 UTC (permalink / raw)



Has anyone ever intefaced a C object module with an (Ada83) Ada
program in the Rational Apex or Verdix VadsCross environment? I am
planning to just include the object module in the compilation view and
use the  Pragma Interface (C, c-function-name). Will this work?




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: C interface - Apex/Verdix
  1997-05-29  0:00 ` Christopher Green
@ 1997-05-30  0:00   ` Mark Bennison
  1997-06-04  0:00   ` Gary Brumfield
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Bennison @ 1997-05-30  0:00 UTC (permalink / raw)



cgreen@yosemite.atc.com (Christopher Green) wrote:
>In article <338ce5d2.87925678@news.mhv.net>,
>Paul Van Bellinghen <pvanbell@mhv.net> wrote:
>>Has anyone ever intefaced a C object module with an (Ada83) Ada
>>program in the Rational Apex or Verdix VadsCross environment? I am
>>planning to just include the object module in the compilation view and
>>use the  Pragma Interface (C, c-function-name). Will this work?
>
>You may also need pragma Interface_Name (c-function-name, "actual-name");
>this will account for situations where VADS name-mangling doesn't yield
>the correct name for the C function.
>

Another thing that may be relevant is that you will need ( in 
VadsCross, I haven't used Apex ) to add a WITH directive to the ada.lib 
file ( using a.info -i ) to give the location of your 'C' object code to 
the linker.

Mark.
-- 
Mark Bennison,           +-----------------------------------+
Technical Consultant,    | All opinions expressed are my own |
EASAMS Software Systems. +-----------------------------------+
"Death is a fickle hen, and random are her eggs" - Armando Iannucci
Remove '.no.spam' to return e-mail





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: C interface - Apex/Verdix
  1997-05-29  0:00 ` Christopher Green
  1997-05-30  0:00   ` Mark Bennison
@ 1997-06-04  0:00   ` Gary Brumfield
  1997-06-06  0:00     ` Arthur Schwarz
  1997-06-07  0:00     ` Robert Dewar
  1 sibling, 2 replies; 6+ messages in thread
From: Gary Brumfield @ 1997-06-04  0:00 UTC (permalink / raw)
  To: Christopher Green


Christopher Green wrote:
> 
> Apex for Ada 95 has pragma Import, which is portable.
> 
> (Language is a predefined package on VADS that provides the correct
> prefixes for external names; for example, on SunOS 4 hosts,
> Language.C_Subp_Prefix is the string "_".)
> 

I am coding in Ada95 (for the first time) using the Apex Ada 2.2.3A
compiler and need to interface with C/C++ code compiled using the Sun
compiler.  I am able to link a main Ada program with a C procedure using
the pragma Import but I have to supply the "mangled" C linker_name.  To
get this name I have to use the UNIX "nm" command on the object file. 
This seems dangerous if the C compiler ever decides to change the way
this "mangled" name is generated.  Do you know of a better way around
this?  My platform is Sun Solaris 2.5.1.  Can I use this VADS language
package and if so, where is it?

  NAME         MANGLED NAME
 ---------     ---------------
 c_routine     __0FJc_routinev


Notice that my "mangled" name also has a "v" suffix in addition to a
"__0FJ" prefix.

Also, do you know if Apex Ada will support a C++ main program
interfacing with Ada95?  This does work in GNAT when "adainit" and
"adafinal" are used.
-- 

Gary B.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: C interface - Apex/Verdix
  1997-06-04  0:00   ` Gary Brumfield
@ 1997-06-06  0:00     ` Arthur Schwarz
  1997-06-07  0:00     ` Robert Dewar
  1 sibling, 0 replies; 6+ messages in thread
From: Arthur Schwarz @ 1997-06-06  0:00 UTC (permalink / raw)
  To: Gary Brumfield


Gary Brumfield wrote:
> 
> Christopher Green wrote:
> >
> 
> I am coding in Ada95 (for the first time) using the Apex Ada 2.2.3A
> compiler and need to interface with C/C++ code compiled using the Sun


FYI: Rational does NOT have a validated Ada95 compiler. Looking at
the validation results posted in SEIC,
"http://sw-eng.falls-church.va.us/AdaIC/", it appears that
the Rational Ada compiler has not passed a single Ada95 test from 
the ACVC. Rational has said that they will have a validated compiler 
in June, 97. I have no further information concerning this.

The note is written to make you aware that if you intend to treat
the Rational Ada95 compiler for anything but 'toy' projects, you
might be subject to future recoding efforts. 

art schwarz
aschwarz@acm.org




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: C interface - Apex/Verdix
  1997-06-04  0:00   ` Gary Brumfield
  1997-06-06  0:00     ` Arthur Schwarz
@ 1997-06-07  0:00     ` Robert Dewar
  1 sibling, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1997-06-07  0:00 UTC (permalink / raw)



Gary says

<<I am coding in Ada95 (for the first time) using the Apex Ada 2.2.3A
compiler and need to interface with C/C++ code compiled using the Sun
compiler.  I am able to link a main Ada program with a C procedure using
the pragma Import but I have to supply the "mangled" C linker_name.  To
get this name I have to use the UNIX "nm" command on the object file. 
This seems dangerous if the C compiler ever decides to change the way
this "mangled" name is generated.  Do you know of a better way around
this?  My platform is Sun Solaris 2.5.1.  Can I use this VADS language
package and if so, where is it?
>>

This kind of manual mangling is not required in Ada 95 to interface with
C code. Assuming you have a full language implementation that supports
C as a language name in Import, then using the name as it is used in
the C program as the External_Name parameter (as opposed to the Linker_Name)
must work correctly. If it does not, then this is a clear bug that should be
reported to the vendor.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1997-06-07  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-29  0:00 C interface - Apex/Verdix Paul Van Bellinghen
1997-05-29  0:00 ` Christopher Green
1997-05-30  0:00   ` Mark Bennison
1997-06-04  0:00   ` Gary Brumfield
1997-06-06  0:00     ` Arthur Schwarz
1997-06-07  0:00     ` Robert Dewar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox