From: Brian Drummond <brian@shapes.demon.co.uk>
Subject: Re: Ada as glue ? logical approach ?
Date: Sun, 29 Jan 2012 13:10:50 +0000 (UTC)
Date: 2012-01-29T13:10:50+00:00 [thread overview]
Message-ID: <jg3ggq$pht$1@dont-email.me> (raw)
In-Reply-To: 9e698480-636a-419f-9b50-400b322de8d4@dp8g2000vbb.googlegroups.com
On Sat, 28 Jan 2012 20:53:21 -0800, Patrick wrote:
> Hi Everyone
>
> I have been studying ada for sometime now but I have no experience
> coding with it.
>
> It doesn't look like there are all the library bindings i want but I
> am wondering if this really matters.
>
> Someone could write a full binding for a library but could someone also
> not just use the import pragma to "grab onto" the existing C library
> APIs?
>
> This would be a bit like ctypes in Python correct ? Are other list
> members writing their own 'as needed' partial bindings? Is this a
> logical approach? -Patrick
In addition to agreeing with the other comments - especially the
recommendation to make a "thick binding" to give you an Ada-like
interface, rather than exposing the C-like details any more widely than
necessary...
if you use a recent enough version of GCC, you can compile a C or C++
header file with the -fdump-ada-spec or -fdump-ada-spec-slim options, and
it will automatically generate the thin binding (with import pragmas) for
you. The -slim version just compiles the header you give it; the fat
version compiles the transitive closure (i.e. all the header files it
imports too, recursively)
The result is not perfect; very good on plain C but it doesn't handle C++
templates very well (last time I looked) but even then, it saves a lot of
time.
I would implement the Ada binding as a package that uses this, exposing
only Ada types and functions to the rest of your code.
A very simple example :
http://wiki.ada-dk.org/c_bindings_example
If you are importing C rather than C++, ignore the bit about saving the
header as .hpp. (There is another way to force C vs C++, not covered in
the article. Compile a .h file with g++ rather than gcc)
See also
http://www.adacore.com/2009/02/23/gem-59/
- Brian
next prev parent reply other threads:[~2012-01-29 13:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-29 4:53 Ada as glue ? logical approach ? Patrick
2012-01-29 8:26 ` Simon Wright
2012-01-29 9:46 ` mockturtle
2012-01-29 13:10 ` Brian Drummond [this message]
2012-01-29 13:57 ` Patrick
2012-01-29 16:51 ` mockturtle
2012-01-30 0:26 ` Patrick
2012-02-01 2:19 ` BrianG
2012-02-01 4:07 ` Patrick
2012-02-01 6:05 ` tmoran
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox