[Haskell-cafe] [ANN] Haskell FFI Tutorial

Richard A. O'Keefe ok at cs.otago.ac.nz
Thu Nov 13 01:03:19 UTC 2014


On 12/11/2014, at 8:37 pm, Donn Cave <donn at avvanta.com> wrote:
> 
> It works to a certain extent with integral types, because I can
> determine the size of the C field and assign an appropriate Haskell
> foreign integral type.  I used it to generate a module for struct termios,
> for which I've been using hsc2hs, and it did better than hsc2hs in
> an unexpected way - hsc2hs #type maps "unsigned long" to "Word32",
> but on MacOS X the field size is 8 bytes.

That’s not quite right.
compile with “cc -m64” and the field size is 8 bytes, but
compile with “cc -m32” and the field size is 4 bytes.

(This actually strikes me as a flaw in Mac OS X:
‘typedef unsigned long tcflag_t;’ should have been
‘typedef uint32_t tcflag_t;'
because there’s no _reason_ for the field size to change
this way.)

The fact that the sizes of things can vary between compilation
environments on the same host is one of the reasons tools like
hsc2hs are hard.


More information about the Haskell-Cafe mailing list