comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Johnson <mark_h_johnson@raytheon.com>
Subject: Re: Automatic generation of C bindings
Date: Mon, 27 Aug 2001 13:00:08 -0500
Date: 2001-08-27T13:00:08-05:00	[thread overview]
Message-ID: <3B8A8AA8.9B588C2A@raytheon.com> (raw)
In-Reply-To: MPG.15f1e6962b09031e9896c5@news.cis.dfn.de

Jano wrote:

> Hello all.
>
> I'm looking for a tool that generates ada specs from c headers to
> allow link to  c libraries.
>

Good luck on "automatic translation". The best you will get is something
that is "close", but requires a lot of debugging to get it correct.
Things that tend to be OK include...
 - access to external symbols and functions [see caution]
 - layout of simple data structures
The caution on external symbols gets into the use of underscores (_) to
prefix symbols in some compilers, symbol crunching on some systems, and
so on. You may need to use pragma Import, Export, and Convention (or
other compiler specific ones) to make everything right.

Problems I've seen include...
 - macros that manipulate access to the data (e.g., a value is "true" if
it is equal to "X" after mask "Y")
 - functions that use (void*) to pass data dependent on other arguments
 - the whole argv mechanism
 - alignment of data
 - bit and byte order
 - multiple layers of macros
These you are better off doing manually. If you are using gcc on Unix, I
recommend...
 - create a simple C application (test.c) that does what you want
 - gcc -C -E -dD [other switches here] test.c > test.output
 - gcc -C -E -dM [other switches here] test.c | sort > test.macros
[I assume other C compilers have similar options for capturing
preprocessor output]
The file "test.output" captures the expanded source code w/ comments.
The file "test.macros" captures the just the macro definitions. This
plus, some understanding of how your C and Ada compiler lays out data,
passes parameters, and so on will give you the clues you need to do this
task.

Better yet, if there is some specific Ada to C bindings you are looking
for, ask for that & someone should be able to help you (e.g., Florist
for Posix bindings).
  --Mark





  reply	other threads:[~2001-08-27 18:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-25 15:45 Automatic generation of C bindings Jano
2001-08-27 18:00 ` Mark Johnson [this message]
2001-08-29 18:25   ` Jano
2001-09-08 12:23     ` Stefan Skoglund
replies disabled

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