comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: "extern" procedure in ada
Date: 30 Sep 2002 10:37:14 -0400
Date: 2002-09-30T14:47:37+00:00	[thread overview]
Message-ID: <u7kh3o86d.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: an2c4e$52l$1@dns3.cae.ca

"Bernard Azria" <azria@cae.ca> writes:

> I am looking for the equivallent of an "extern" definition procedure in
> C for ADA.
> 
> In other words, how could I define an external procedure to my program
> without "withing" the package where it is defined ( I have only the "obj'
> and the "ali" file of this procedure in a library)

I gather you are trying to use a library that you don't have source
for? Be careful not to violate your license to use the library.

In order to call any subprogram from Ada, you need the specification of
the subprogram; the parameter types and return type.

If you have the source code of the subprograms in Ada, you have the
subprogram specifications.

If you don't have the source code (your case), you need to write the
specifications yourself, and tell the compiler to get the bodies of
the subprogram from the library. pragma Import is precisely what you
need to use for this task.

For a library package, it is usually convenient to group the
specifications in an Ada package. The package spec contains all the
subprogram specs, and all the 'pragma Import' statements.

If you are only calling a few subprograms from one place, putting the
subprogram specifications in the same package where you are calling
them makes sense.

> Would it be an kind of : pragma import ( ADA, procedure_name )

Yes, exactly. Although, if the library .o is compiled by a different
compiler than your code, this is not guarranteed to work. You might
need your vendor to provide an "Ada_GNAT" convention.

-- 
-- Stephe



  parent reply	other threads:[~2002-09-30 14:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-27 19:40 "extern" procedure in ada Bernard Azria
2002-09-28  2:28 ` Jim Rogers
2002-09-28  3:13 ` SteveD
2002-09-28  3:47 ` sk
2002-09-30 14:37 ` Stephen Leake [this message]
2002-09-30 22:39   ` Bernard Azria
2002-10-01 19:57     ` Simon Wright
2002-10-02  1:49       ` Jeffrey Carter
2002-10-02 15:13         ` Bernard Azria
2002-10-02 18:56           ` Jeffrey Carter
replies disabled

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