declaring C enum types

Manuel M T Chakravarty chak at cse.unsw.edu.au
Thu Oct 17 04:18:45 EDT 2002


Antony Courtney <antony at apocalypse.org> wrote,

> A relatively mundane question:
> 
> Is there a preferred means of writing a foreign import declaration for a 
> C function with a prototype that takes an "enum" argument?
> 
> i.e., in C we have:
> 
> enum bar {
>    GOOD,  BAD
> };
> 
> void foo(enum bar x);

That's exactly the kind of scenario for which I have written
C->Haskell:

  http://www.cse.unsw.edu.au/~chak/haskell/c2hs

Using C->Haskell, you write into the binding module

  {#enum bar as Bar#}

run it through the tool and get a Haskell data definition
for `Bar', so that you can safely marshal between C's bar
and Haskell's Bar.  (See also the corresponding section in
the manual
<http://www.cse.unsw.edu.au/~chak/haskell/c2hs/docu/c2hs-3.html#ss3.5>.)

Manuel



More information about the FFI mailing list