
I would like to know whether there is a good way to marshal the following structure to C without using pointer arithmetic done by a programmer (as opposed to a tool).
Here is an example with poke. It's completely useless, except for
demonstration :) You have a global variable in C that receives
data in a struct, and a 'print' function that prints it.
*** C header: ***
#define NPOWERS 6
typedef struct {
double number;
double negpowers[NPOWERS];
} power_struct;
extern power_struct np;
void print_np (void);
*** C definition: ***
power_struct np;
void print_np (void)
{
int i;
printf("\n");
printf ("Negative powers of %g: \n",np.number);
for (i=0;i<=NPOWERS;i++) printf(" %g",np.negpowers[i]);
printf("\n");
}
*** Binding module, with hsc2hs macros: ***
#starttype power_struct
#field number , CDouble
#array_field negpowers , CDouble
#stoptype
#globalvar np ,