comp.lang.ada
 help / color / mirror / Atom feed
* Mixed Ada and C program
@ 2001-06-11 14:33 Joelle Lavergne
  2001-06-11 14:44 ` Marin David Condic
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Joelle Lavergne @ 2001-06-11 14:33 UTC (permalink / raw)


Hello I am pretty new to the Ada world.

I need to build an application using Ada and C. The main application is in
Ada but I need to import C function to Ada and export Ada procedures to C.
My problem is when exporting my Ada procedure to C.

Could anybody give me some info on how to call this Ada procedure from C ?

Thanks





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

* Re: Mixed Ada and C program
  2001-06-11 14:33 Mixed Ada and C program Joelle Lavergne
@ 2001-06-11 14:44 ` Marin David Condic
  2001-06-11 15:03 ` Joelle Lavergne
  2001-06-11 15:10 ` Ted Dennison
  2 siblings, 0 replies; 6+ messages in thread
From: Marin David Condic @ 2001-06-11 14:44 UTC (permalink / raw)


First off, how C calls Ada is not Ada's problem. It is C's problem and can
only ultimately be answered by the C compiler. Second off, there are ways of
exporting Ada code that make it accessible to other languages, but there are
likely to be some implementation specifics to go with it. (We can make Ada
look to C as if it were C, but there may be problems depending on the two
specific compilers used.) If you post the specifics of your platform,
someone here will probably be able to give you an answer. State the Ada
compiler/version, the C compiler/version the hardware and OS platform.

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Joelle Lavergne" <jlavergne@drs.ca> wrote in message
news:rF4V6.895$j6.75257@news...
> Hello I am pretty new to the Ada world.
>
> I need to build an application using Ada and C. The main application is in
> Ada but I need to import C function to Ada and export Ada procedures to C.
> My problem is when exporting my Ada procedure to C.
>
> Could anybody give me some info on how to call this Ada procedure from C ?
>
> Thanks
>
>





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

* Re: Mixed Ada and C program
  2001-06-11 14:33 Mixed Ada and C program Joelle Lavergne
  2001-06-11 14:44 ` Marin David Condic
@ 2001-06-11 15:03 ` Joelle Lavergne
  2001-06-11 15:19   ` Ted Dennison
  2001-06-12  2:40   ` DuckE
  2001-06-11 15:10 ` Ted Dennison
  2 siblings, 2 replies; 6+ messages in thread
From: Joelle Lavergne @ 2001-06-11 15:03 UTC (permalink / raw)


I  have answered my question... I will pass the adress of the Ada procedure
to the C function.

Thanks

Joelle Lavergne <jlavergne@drs.ca> wrote in message
news:rF4V6.895$j6.75257@news...
> Hello I am pretty new to the Ada world.
>
> I need to build an application using Ada and C. The main application is in
> Ada but I need to import C function to Ada and export Ada procedures to C.
> My problem is when exporting my Ada procedure to C.
>
> Could anybody give me some info on how to call this Ada procedure from C ?
>
> Thanks
>
>





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

* Re: Mixed Ada and C program
  2001-06-11 14:33 Mixed Ada and C program Joelle Lavergne
  2001-06-11 14:44 ` Marin David Condic
  2001-06-11 15:03 ` Joelle Lavergne
@ 2001-06-11 15:10 ` Ted Dennison
  2 siblings, 0 replies; 6+ messages in thread
From: Ted Dennison @ 2001-06-11 15:10 UTC (permalink / raw)


In article <rF4V6.895$j6.75257@news>, Joelle Lavergne says...
>I need to build an application using Ada and C. The main application is in
>Ada but I need to import C function to Ada and export Ada procedures to C.
>My problem is when exporting my Ada procedure to C.

Exporting is somewhat of an advanced topic, so its a shame you have to use this
to learn Ada. But it could have been worse...

Since your main is in Ada, it should be relatively easy. Just use "pragma Export
(C, subprogram_name);" to export subprogram_name to C, as detailed in Annex B,
section 1 of the LRM. If you have parameters to pass, a *thourough* reading of
the implementation advice in Annex B, section 3 of the LRM should tell you how
they will be mapped. If you don't have a dead-tree version of the LRM handy,
there's one online at http://www.ada-auth.org/arm-html/RM-TOC.html .

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

* Re: Mixed Ada and C program
  2001-06-11 15:03 ` Joelle Lavergne
@ 2001-06-11 15:19   ` Ted Dennison
  2001-06-12  2:40   ` DuckE
  1 sibling, 0 replies; 6+ messages in thread
From: Ted Dennison @ 2001-06-11 15:19 UTC (permalink / raw)


In article <h55V6.898$j6.76089@news>, Joelle Lavergne says...
>
>I  have answered my question... I will pass the adress of the Ada procedure
>to the C function.

I would still highly suggest doing either a "pragma Export (C, " or "pragma
Convention (C,". Otherwise you might find yourself hosing your program's stack.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

* Re: Mixed Ada and C program
  2001-06-11 15:03 ` Joelle Lavergne
  2001-06-11 15:19   ` Ted Dennison
@ 2001-06-12  2:40   ` DuckE
  1 sibling, 0 replies; 6+ messages in thread
From: DuckE @ 2001-06-12  2:40 UTC (permalink / raw)


While you can certainly do this, you shouldn't have to go to the trouble.

You should be able to export the procedure or function directly:

  PROCEDURE My_Procedure;
  PRAGMA Export( C, My_Procedure );

  PROCEDURE My_Procedure IS
  BEGIN
    -- Do_Something
    NULL;
  END My_Procedure;

While I haven't done this with 'C', I have exported Ada functions and
procedures using 'C' conventions and then linked the functions and
procedures with Delphi.  I would think things would work the same way.

SteveD.

"Joelle Lavergne" <jlavergne@drs.ca> wrote in message
news:h55V6.898$j6.76089@news...
> I  have answered my question... I will pass the adress of the Ada
procedure
> to the C function.
>
> Thanks
>
> Joelle Lavergne <jlavergne@drs.ca> wrote in message
> news:rF4V6.895$j6.75257@news...
> > Hello I am pretty new to the Ada world.
> >
> > I need to build an application using Ada and C. The main application is
in
> > Ada but I need to import C function to Ada and export Ada procedures to
C.
> > My problem is when exporting my Ada procedure to C.
> >
> > Could anybody give me some info on how to call this Ada procedure from C
?
> >
> > Thanks
> >
> >
>
>





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

end of thread, other threads:[~2001-06-12  2:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-11 14:33 Mixed Ada and C program Joelle Lavergne
2001-06-11 14:44 ` Marin David Condic
2001-06-11 15:03 ` Joelle Lavergne
2001-06-11 15:19   ` Ted Dennison
2001-06-12  2:40   ` DuckE
2001-06-11 15:10 ` Ted Dennison

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