From: Ludovic Brenta <ludovic.brenta@insalien.org>
Subject: Re: trying to call HDF5 from ada -- problems with constants
Date: Thu, 26 Aug 2004 20:29:19 +0200
Date: 2004-08-26T20:30:25+02:00 [thread overview]
Message-ID: <877jrlkb28.fsf@insalien.org> (raw)
In-Reply-To: cgkii4$lga$1@fsuj29.rz.uni-jena.de
Christopher Broeg writes:
> tx. I just realized that with gnat I can import the constants
> directly. I realized that the ada specifications in the RM do never
> explicitly mention functions or procedures with respect to pragma
> import. So I did:
>
> H5T_STD_I32BE_g : Hid_t;
> pragma Import(C,H5T_STD_I32BE_g , "H5T_STD_I32BE_g");
>
> and it works! All you have to do is call H5open manually, which is
> done automatically with the c preprocessor. Is this behaviour
> compiler-dependant, or ADA standard?
It is Ada standard, but the implementation depends on how well the Ada
compiler, C compiler, and linker get along with each other. GNAT, GCC
and GNU ld get _very_ well along together :)
BTW, you can call H5open from within elaboration code if that helps
you, like this:
package P is
pragma Elaborate_Body (P); -- force elaboration of the body (optional)
H5T_STD_I32BE_g : Hid_t;
pragma Import(C,H5T_STD_I32BE_g , "H5T_STD_I32BE_g");
end P;
package body P is
begin
H5T_STD_I32BE_g := H5open; -- elaboration code
end P;
The elaboration runs before your main subprogram.
> I'm surprised, because there was this long thread on this very topic
> explicitly stating that ada cannot import c constants... But I guess
> it only referred to preprocessor constants. All "variing" constants
> are of course real c constants visible in the library.
That's right, Ada cannot see preprocessor constants, she can only see
C's "static" variables. This is really done by the linker.
--
Ludovic Brenta.
next prev parent reply other threads:[~2004-08-26 18:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-25 13:38 trying to call HDF5 from ada -- problems with constants Christopher Broeg
2004-08-25 16:35 ` Brian Catlin
2004-08-26 8:04 ` Christopher Broeg
2004-08-26 11:00 ` Jeff C,
2004-08-26 11:46 ` Christopher Broeg
2004-08-26 18:29 ` Ludovic Brenta [this message]
2004-08-26 19:20 ` Randy Brukardt
2004-08-27 0:54 ` Jeffrey Carter
2004-08-27 11:32 ` Christopher Broeg
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox