When interfacing with C with other languages, it is often necessary to
write wrapper functions to access C structs because there are no
general (and free) tools available which can generate structure layout
information from C sources.

For example, suppose that I want to write Ada code which uses the
poll(2) from POSIX.  POSIX only guarantees that the following fields
are available in struct pollfd:

| int    fd       The following descriptor being polled. 
| short  events   The input event flags (see below). 
| short  revents  The output event flags (see below). 

Additional members are permitted, and the fields can be order.  In
order to create a portable Ada interface, I have to write a short C
program which uses sizeof and offsetof to extract the structure
layout.  In theory, it is possible to create compile-time-only tests
suitable for cross-compilation (compile-time constant expressions,
invalid zero-length arrays, and a binary search), but this is rather
messy.  This is probably one of the reason why the GNAT run-time
library currently uses manually translated record definitions, which
reduces its portability.

Are there any objections to exporting structure layout from GCC, in a
format which can be parsed in a straightforward manner?  Such a patch
could be used as a GPL circumvention device, but I'm not sure how
relevant this is in practice because GCC follows published ABIs, so a
clean-room reimplementation would be straightforward (IOW, there isn't
much to lose for us because our competetive edge is pretty minimal).

Reply via email to