comp.lang.ada
 help / color / mirror / Atom feed
* Automatic generation of C bindings
@ 2001-08-25 15:45 Jano
  2001-08-27 18:00 ` Mark Johnson
  0 siblings, 1 reply; 4+ messages in thread
From: Jano @ 2001-08-25 15:45 UTC (permalink / raw)


Hello all.

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

Someone can advice me? I'm downloading a c2ada from adapower, but I 
haven't received it yet complete, and I'm wondering if this is the 
appropriate tool. BTW, wasn't win32ada mainly automatic generated?

Thanks,

----------------------
Jano
402450@cepsz.unizar.es
----------------------



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

* Re: Automatic generation of C bindings
  2001-08-25 15:45 Automatic generation of C bindings Jano
@ 2001-08-27 18:00 ` Mark Johnson
  2001-08-29 18:25   ` Jano
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Johnson @ 2001-08-27 18:00 UTC (permalink / raw)


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





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

* Re: Automatic generation of C bindings
  2001-08-27 18:00 ` Mark Johnson
@ 2001-08-29 18:25   ` Jano
  2001-09-08 12:23     ` Stefan Skoglund
  0 siblings, 1 reply; 4+ messages in thread
From: Jano @ 2001-08-29 18:25 UTC (permalink / raw)


Mark Johnson ha escrito esto previamente:

> 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.

Thanks for your comments. I wasn't expecting to face so hard a problem.

> 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).

My case was easy, in the end. My C sources are mainly #defines of 
constants. (Ids of resources, for use in Win32). I've write a simple 
translator (using Ada :) which, for now, suits my needs. But, that has 
make me think of more general solutions, just in case...

----------------------
Jano
402450@cepsz.unizar.es
----------------------



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

* Re: Automatic generation of C bindings
  2001-08-29 18:25   ` Jano
@ 2001-09-08 12:23     ` Stefan Skoglund
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Skoglund @ 2001-09-08 12:23 UTC (permalink / raw)


Jano wrote:
> My case was easy, in the end. My C sources are mainly #defines of
> constants. (Ids of resources, for use in Win32). I've write a simple
> translator (using Ada :) which, for now, suits my needs. But, that has
> make me think of more general solutions, just in case...

Usch , i usually writes such things as enums or static char constants,
i try to avoid cpp in this case.





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

end of thread, other threads:[~2001-09-08 12:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-25 15:45 Automatic generation of C bindings Jano
2001-08-27 18:00 ` Mark Johnson
2001-08-29 18:25   ` Jano
2001-09-08 12:23     ` Stefan Skoglund

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