declaring C enum types
Antony Courtney
antony at apocalypse.org
Wed Oct 16 10:30:15 EDT 2002
Hi all,
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);
I recall from some sessions with gdb some years ago that most C
compilers encode enums as if they were unsigned short values (i.e. 16
bits on most platforms). Does anyone know off hand:
- Is it a safe, portable assumption that enums will always be
encoded as an unsigned short or 16-bit word?
- If so, should one prefer "Word16" or "UShort" on the Haskell side
for the foreign import declaration?
- If not, then how should enum values be declared in the FFI?
Appologies if the FFI addresses this issue and I have overlooked it.
Thanks,
-antony
--
Antony Courtney
Grad. Student, Dept. of Computer Science, Yale University
antony at apocalypse.org http://www.apocalypse.org/pub/u/antony
More information about the FFI
mailing list