comp.lang.ada
 help / color / mirror / Atom feed
* including C routines in Ada (newbie ask for assistance)
@ 2001-05-07 10:57 Noam Kloos
  2001-05-07 13:01 ` Marc A. Criley
  2001-05-09  5:39 ` Simon Wright
  0 siblings, 2 replies; 6+ messages in thread
From: Noam Kloos @ 2001-05-07 10:57 UTC (permalink / raw)


Hi Once I had someone show me how to write routines in C and import
them into Ada source with pragma Import(....);
I know how to do a system call pragma import(C,C_System,"system"); but
how do I access a c source file I have written myself?

Noam Kloos.
Someone who is very pleased with Ada.




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

* Re: including C routines in Ada (newbie ask for assistance)
  2001-05-07 10:57 including C routines in Ada (newbie ask for assistance) Noam Kloos
@ 2001-05-07 13:01 ` Marc A. Criley
  2001-05-07 14:00   ` Marin David Condic
  2001-05-09  5:39 ` Simon Wright
  1 sibling, 1 reply; 6+ messages in thread
From: Marc A. Criley @ 2001-05-07 13:01 UTC (permalink / raw)


Noam Kloos wrote:
> 
> Hi Once I had someone show me how to write routines in C and import
> them into Ada source with pragma Import(....);
> I know how to do a system call pragma import(C,C_System,"system"); but
> how do I access a c source file I have written myself?

If you're using GNAT, look in the GNAT User Guide in the section on
"Mixed Language Programming/Interfacing to C", and look at the
"use_of_import.adb" example in the GNAT examples directory.

Marc A. Criley
Senior Staff Engineer
Quadrus Corporation
www.quadruscorp.com



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

* Re: including C routines in Ada (newbie ask for assistance)
  2001-05-07 13:01 ` Marc A. Criley
@ 2001-05-07 14:00   ` Marin David Condic
  2001-05-07 17:39     ` David Starner
  0 siblings, 1 reply; 6+ messages in thread
From: Marin David Condic @ 2001-05-07 14:00 UTC (permalink / raw)


Good advice. Its also important to observe that whatever functions are
written in C are outside the scope of Ada, and that one needs to figure out
the compilation/linking of C code into a callable library strictly from the
C perspective. Once you have a callable/linkable file Ada can take over &
specify how the Ada program can reach the function. The specifics, of
course, are going to be very dependent on the implementations of the two
languages.

That is to say that two mismatched compilers might never be able to hook
code together since there is nothing mandatory about how a C compiler must
present its interface {calling sequence & parameter passing} and the Ada
compiler attempting to connect to it via pragmas is only going to do so via
some specific conventions that it knows about. Gnat will know about the gcc
method of interfacing, which is probably the same as what the underlying OS
uses for its C-written calls, but with some other compiler at the other end,
you get no guarantees. So its important to state what the environment is
when trying to figure this stuff out.

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/


"Marc A. Criley" <mcqada@earthlink.net> wrote in message
news:3AF68F86.7DA2B0C9@earthlink.net...
> Noam Kloos wrote:
> >
> > Hi Once I had someone show me how to write routines in C and import
> > them into Ada source with pragma Import(....);
> > I know how to do a system call pragma import(C,C_System,"system"); but
> > how do I access a c source file I have written myself?
>
> If you're using GNAT, look in the GNAT User Guide in the section on
> "Mixed Language Programming/Interfacing to C", and look at the
> "use_of_import.adb" example in the GNAT examples directory.
>






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

* Re: including C routines in Ada (newbie ask for assistance)
  2001-05-07 14:00   ` Marin David Condic
@ 2001-05-07 17:39     ` David Starner
  2001-05-07 21:17       ` Marin David Condic
  0 siblings, 1 reply; 6+ messages in thread
From: David Starner @ 2001-05-07 17:39 UTC (permalink / raw)


On Mon, 7 May 2001 10:00:19 -0400, Marin David Condic <marin.condic.auntie.spam@pacemicro.com> wrote:
> That is to say that two mismatched compilers might never be able to hook
> code together since there is nothing mandatory about how a C compiler must
> present its interface {calling sequence & parameter passing} and the Ada
> compiler attempting to connect to it via pragmas is only going to do so via
> some specific conventions that it knows about. Gnat will know about the gcc
> method of interfacing, which is probably the same as what the underlying OS
> uses for its C-written calls, but with some other compiler at the other end,
> you get no guarantees. 

GCC works very hard to support the system ABI. On most systems, the C 
ABI is standardized and very well supported. Note that there's nothing
mandatory about how an Ada compiler must present its interface, and
except in rare cases (DEC Ada & GNAT) two Ada compilers won't share an
interface.

-- 
David Starner - dstarner98@aasaa.ofe.org
Pointless website: http://dvdeug.dhis.org
"I don't care if Bill personally has my name and reads my email and 
laughs at me. In fact, I'd be rather honored." - Joseph_Greg



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

* Re: including C routines in Ada (newbie ask for assistance)
  2001-05-07 17:39     ` David Starner
@ 2001-05-07 21:17       ` Marin David Condic
  0 siblings, 0 replies; 6+ messages in thread
From: Marin David Condic @ 2001-05-07 21:17 UTC (permalink / raw)


Oh, I'll agree that in most cases things are going to line up nicely on a
given platform. I'm just observing that there is nothing *mandatory* about
this. It *might* work just fine. Then again, it might not. There's no way to
be sure unless you specify the compilers & system involved. For a given
platform, you might be able to conceive of a dozen possible ways of calling
a C function and passing it parameters. Which of those dozen ways actually
works will depend on the code generated by the C compiler. AFAIK, there's no
government certification board or IEEE committee or any other agency that
tests all compilers to see that they use some prescribed subprogram calling
convention and spanks the implementations that disobey. :-)

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/


"David Starner" <dvdeug@x8b4e53cd.dhcp.okstate.edu> wrote in message
news:9d6mkr$71u1@news.cis.okstate.edu...
>
> GCC works very hard to support the system ABI. On most systems, the C
> ABI is standardized and very well supported. Note that there's nothing
> mandatory about how an Ada compiler must present its interface, and
> except in rare cases (DEC Ada & GNAT) two Ada compilers won't share an
> interface.
>






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

* Re: including C routines in Ada (newbie ask for assistance)
  2001-05-07 10:57 including C routines in Ada (newbie ask for assistance) Noam Kloos
  2001-05-07 13:01 ` Marc A. Criley
@ 2001-05-09  5:39 ` Simon Wright
  1 sibling, 0 replies; 6+ messages in thread
From: Simon Wright @ 2001-05-09  5:39 UTC (permalink / raw)


serious@clerk.com (Noam Kloos) writes:

> Hi Once I had someone show me how to write routines in C and import
> them into Ada source with pragma Import(....);
> I know how to do a system call pragma import(C,C_System,"system"); but
> how do I access a c source file I have written myself?

For a start, you write similar pragma Imports for your own
functions. Then you have to link against the object files.

If you are using GNAT, and you have your main Ada program in foo.adb
and your C in bar.c, you would need

  gcc -c bar.c
  gnatmake foo -largs bar.o

(to start with, it can get more complicated of course!)



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

end of thread, other threads:[~2001-05-09  5:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-07 10:57 including C routines in Ada (newbie ask for assistance) Noam Kloos
2001-05-07 13:01 ` Marc A. Criley
2001-05-07 14:00   ` Marin David Condic
2001-05-07 17:39     ` David Starner
2001-05-07 21:17       ` Marin David Condic
2001-05-09  5:39 ` Simon Wright

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