[C2hs] C2hs and c 'struct' declarations

Thomas DuBuisson thomas.dubuisson at gmail.com
Sun Sep 20 19:39:21 EDT 2009


Hello c2hs!

I'm having an issue when using get and set hooks.  Take the following
example c code:

    typedef struct {
        int x;
        int y;
    } point;

This has easy bindings:

    {#pointer *point as Point#}

    getX :: Point -> IO CInt
    getX = {#get point->x#}

    setX :: Point -> CInt -> IO ()
    setX p i = {#set point->x} p i

But what if the header file doesn't typedef?

    struct point {
        int x;
        int y;
    };

It seems c2hs can't bind to these data structures, the straight
forward way of replacing 'point' with 'struct point' isn't parsed.
Any combination of parens or quotes to make it parse as a single token
haven't worked - also I see nothing in the tutorial.  Any advice?

Thomas


More information about the C2hs mailing list