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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.205.138 with SMTP id fq10mr25483255qab.1.1372669355105; Mon, 01 Jul 2013 02:02:35 -0700 (PDT) X-Received: by 10.49.97.34 with SMTP id dx2mr671070qeb.42.1372669355089; Mon, 01 Jul 2013 02:02:35 -0700 (PDT) Path: border1.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!j2no3149109qak.0!news-out.google.com!f7ni121qai.0!nntp.google.com!j2no3149104qak.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 1 Jul 2013 02:02:34 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=155.253.16.227; posting-account=uPViEgkAAACC04vaTYL5Kyk76brV1MA_ NNTP-Posting-Host: 155.253.16.227 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Thick bindings to a C library and gnattest: suggestions? From: ziotom78@gmail.com Injection-Date: Mon, 01 Jul 2013 09:02:35 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Original-Bytes: 3661 Xref: number.nntp.dca.giganews.com comp.lang.ada:182170 Date: 2013-07-01T02:02:34-07:00 List-Id: Hi to everybody, I am a novice Ada programmer which is trying to convert a C++ code into an Ada program. The C++ code relies on a C library which reads and writes vectors of numeric data in binary format (CFITSIO), for which I am developing a set of "thick" Ada bindings, named AdaFITS. Overall my experience is great: I feel Ada orders of magnitude more secure and "nicer" than C++ (with its odd syntax and complex constructs). There are a few things for which I do not know what is the best "Ada"-ish way to do them, and I would like to ask for the advice of some experts. First question: the vectors used by the CFITSIO library are sometimes huge (millions of elements), sometimes very small (~ 10 elements). I decided to always allocate them on the heap, using declarations like these: subtype Double is Interfaces.C.double; type Double_Array is array (Positive range <>) of Interfaces.C.double; pragma Convention (C, Double_Array); type Double_Array_Ptr is access Double_Array; (similar declarations exist for arrays of integers/long...), and then using "new Double_Array" whenever I need to allocate room for an array. Every binding function only uses Double_Array_Ptr. Is this the best way to do this in Ada? Every text I read about Ada says to stay away from objects allocated on the heap, but I do not see any other solution here. Second question. I run gnattest periodically to keep the list of tests updated with the functions I am implementing. Gnattest is smart enough not to overwrite the existing implementations of my tests, however it does keep rewriting two things: 1. The project "gnattest/harness/test_driver.gpr", where I put the "-lcfitsio" linker switch to link the C library. Understandably, not having such a switch causes a lot of undefined references during the linking phase. 2. The list of "with ..." clauses at the beginning of the .adb file implementing the tests (in the subdir "gnattest/tests"). I need at least to include the library I am testing (AdaFITS), as well as a few packages I implemented to ease comparisons between objects like the Double_Array_Ptr above and other things like Ada.Directories and Ada.Strings.Unbounded. I am sure there is some clever way to solve these two minor points, but so far I have not been able to find it. I tried e.g. to put "-lcfitsio" in the project file of the AdaFITS library, but with no success. (If Ada works like C++, I believe that things like "-lcfitsio" are used when a *program* is built, not a library.) Thanks to everybody for any advice you will give me, Maurizio.