While using c2hsc
and hsc2hs
saves me a lot of work, I've run into some trouble when trying to create bindings for C unions.
For example, given the C structure
typedef struct {
int tag;
union {
char a;
double b;
} v;
} sum_t;
c2hsc
creates the following code for me:
#starttype sum_t
#field tag , CInt
#field v ,
#stoptype
where the v
field is generated empty. Going further down the toolchain via hsc2hs
yields the incorrect
data C'sum_t = C'sum_t{
c'sum_t'tag :: CInt,
c'sum_t'v ::
}
The questions now are
- What is the correct way to write the
.hsc
code manually so I can work with the bindings? - Is there a way I can make
c2hsc
do this automatically?