declaring C enum types

Alastair Reid alastair at
Wed Oct 16 12:28:24 EDT 2002

>     - If not, then how should enum values be declared in the FFI?

What you need to do is run a little autoconf-like program which
constructs a program containing a suitable example, runs it through a
C compiler and tells you what's going on.

hsc comes very close but I'm not certain if it does exactly what you
need.  If not, compiling and running this program should tell you:

#include <stdio.h>

enum test {X,Y};

main() {

        printf("module EnumSize(enumSize) where\n");
        printf("enumSize :: Int\n");
        printf("enumSize = %d\n", sizeof(enum test));


Variants on this theme are figuring out whether it is signed or
unsigned and the size in bits and generating a Haskell type synonym.

Looking at hsc-generated C programs is a great source of tricks
(I stole a few for the Hugs configure code).


More information about the FFI mailing list