comp.lang.ada
 help / color / mirror / Atom feed
From: wheeler@aphrodite.csed.ida.org (David Wheeler)
Subject: Re: C to Ada interfacing
Date: 1996/08/01
Date: 1996-08-01T00:00:00+00:00	[thread overview]
Message-ID: <4tp2lm$6ff@news.ida.org> (raw)
In-Reply-To: 4tnaod$d2n@romeo.logica.co.uk


Paul Hussein (husseinp@logica.co.uk) wrote:
: lees@cts.com (Lee Slaughter) wrote:

: >Hi,

: >I'm not an Ada programmer but need to interface with Ada
: >routines from C (on a VxWorks platform).

: >I'd appreciate it, especially sample code.

Take a look at my Lovelace tutorial.  Chapter 16 has some examples
and a general discussion on calling between C and Ada.  It concentrates on
Ada calling C, but the other direction has quite similar issues.

A key difference is that if the main routine is in C, you need to
call the Ada run-time to get it initialized.  The Ada LRM recommends that
such a function be given a specific name (I think it's ada_init()),
but there's no guarantee that it exists by that name.

A simple approach is to create a main Ada routine that then calls
the main C routine. Voila, you're done.

: >In my probably naive view i'd make a call to someAdaFn( arg )
: >and my Ada-programmer peer would define this function in some 
: >.ada or whatever source file who's
: >object file would be linked in with the C .o stuff, and of
: >course have to take special care to be sure data types align,
: >are in the right order with right number of gaps  and all.

You've got it basically right.  You can ask the Ada compiler to
do a lot of the aligning and gapping for you, but you have to specify
that you want the compiler to use C conventions when calling in or out
of C functions -- otherwise the compiler will use whatever it thinks is best.

: You really need to look in the LRM for your compiler for this sort of
: stuff. Pragma interface to and from C is very troublesome as their is
: little standard support for it.

I think this speaker means Ada 83.  Ada 95 is much nicer about interlanguage
support, I haven't had problems with it at all.  You'll need to get the
details right, so you'd be wise to learn at least the basics of Ada
before writing the interfacing code.  Like anything else, if you want
to interface two widgets, you should have a basic understanding of how
the two widgets work.

Your best bet would be to use the Ada95 pragmas controlling interlanguage
communication; there's a whole section in the Ada Language Reference
Manual that specifically describes how to interface with C programs.
Presuming you don't want to modify the originals, the simplest approach
would be to create small Ada procedures and functions that call the
"real" Ada programs.  Then declare that these trivial procedures and
functions will be called from C, using C types.  Bang.  Done.

Lovelace is at:
 http://lglwww.epfl.ch/Ada/Tutorials/Lovelace/lovelace.htm

--- David A. Wheeler
Net address: wheeler@ida.org





  reply	other threads:[~1996-08-01  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-30  0:00 C to Ada interfacing Lee Slaughter
1996-07-31  0:00 ` PR MITTON
1996-07-31  0:00 ` Paul Hussein
1996-08-01  0:00   ` David Wheeler [this message]
1996-08-01  0:00 ` Theodore E. Dennison
replies disabled

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