Exporting structure layout

Paolo Bonzini bonzini@gnu.org
Wed May 11 19:00:00 GMT 2005


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

Look at AC_COMPUTE_INT.  It should be easy to start from there and do a 
macro like

GCC_COMPUTE_MEMBERS_SIZE_OFFSET([#include <poll.h>],
   [struct pollfd],
   [fd events revents]).

Paolo



More information about the Gcc mailing list