From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a77191f3e4e3079e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!news3.optonline.net!newshosting.com!nx02.iad01.newshosting.com!newsfeed2.ip.tiscali.net!transit0.news.tiscali.nl!tiscali!transit1.news.tiscali.nl!dreader2.news.tiscali.nl!not-for-mail Newsgroups: comp.lang.ada Subject: Re: trying to call HDF5 from ada -- problems with constants References: From: Ludovic Brenta Date: Thu, 26 Aug 2004 20:29:19 +0200 Message-ID: <877jrlkb28.fsf@insalien.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:xmsp/cX3sOf1vxgezheV4TD+pZE= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Tiscali bv NNTP-Posting-Date: 26 Aug 2004 20:30:25 CEST NNTP-Posting-Host: 83.134.239.193 X-Trace: 1093545025 dreader2.news.tiscali.nl 62388 83.134.239.193:60942 X-Complaints-To: abuse@tiscali.nl Xref: g2news1.google.com comp.lang.ada:3041 Date: 2004-08-26T20:30:25+02:00 List-Id: 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.