comp.lang.ada
 help / color / mirror / Atom feed
* Thick bindings to a C library and gnattest: suggestions?
@ 2013-07-01  9:02 ziotom78
  2013-07-01  9:45 ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: ziotom78 @ 2013-07-01  9:02 UTC (permalink / raw)


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.


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

end of thread, other threads:[~2013-07-03 12:02 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-01  9:02 Thick bindings to a C library and gnattest: suggestions? ziotom78
2013-07-01  9:45 ` Dmitry A. Kazakov
2013-07-01 11:11   ` Maurizio Tomasi
2013-07-01 11:41     ` Simon Wright
2013-07-01 12:00       ` Maurizio Tomasi
2013-07-01 12:42         ` Dmitry A. Kazakov
2013-07-01 19:07           ` Simon Wright
2013-07-01 12:32     ` Dmitry A. Kazakov
2013-07-01 12:41       ` Maurizio Tomasi
2013-07-01 12:47       ` Simon Wright
2013-07-02  8:55     ` Georg Bauhaus
2013-07-02  8:33   ` Maurizio Tomasi
2013-07-02  8:58     ` Dmitry A. Kazakov
2013-07-02 16:58     ` Robert A Duff
2013-07-02 17:00     ` Jeffrey Carter
2013-07-01 17:16 ` Jeffrey Carter
2013-07-02  4:24   ` Randy Brukardt
2013-07-02  4:37     ` Shark8
2013-07-02  5:04     ` tmoran
2013-07-02 22:27       ` Randy Brukardt
2013-07-03 12:02   ` Jacob Sparre Andersen
2013-07-02  3:16 ` Jerry
2013-07-02  4:02   ` Shark8

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