Interoperating C-joins in Haskell via c2hsc and hsc2hs
While using c2hsc
and will hsc2hs
save me a lot of work, I ran into some problems when trying to create bindings for C connections.
For example, given the structure of C
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 field is v
generated empty. Going down the tool chain through hsc2hs
results in an incorrect
data C'sum_t = C'sum_t{
c'sum_t'tag :: CInt,
c'sum_t'v ::
}
Now the questions:
- What is the correct way to write the code
.hsc
manually so that I can work with links? - Is there a way to
c2hsc
do this automatically?
source to share
c2hsc
just generates macros bindings-dsl
. Using the documentation there, you should be able to figure out how to write them directly. Consider something like ...
#starttype struct sum_t
#field tag , CInt
#field v.a , CChar
#field v.b , CDouble
#stoptype
The documentation goes on to describe how to manipulate unions using pointers.
source to share