Applicative functor for building C structs with Storable
Adam Langley
agl at imperialviolet.org
Sat Oct 13 13:34:31 EDT 2007
On 10/13/07, Henning Thielemann <lemming at henning-thielemann.de> wrote:
> Are there analogons to ByteString's Put and Get Monads to construct and
> disect binary data in a C struct for exchange with a C program?
The memory layout of structs depends on the ABI of system. You can
take a guess and write code in the Get and Put monads. Your guess will
probably work pretty well within a single architecture (e.g. x86 or
x86-64).
However, the portable way to do this is to get the information from
the C compiler, which is the approach that c2hs[1] and friends use. I
would recommend this unless there's some good reason to think
otherwise. (see [2] for the exact hook)
[1] http://www.cse.unsw.edu.au/~chak/haskell/c2hs/
[2] http://www.cse.unsw.edu.au/~chak/haskell/c2hs/docu/c2hs-2.html#ss2.8
AGL
--
Adam Langley agl at imperialviolet.org
http://www.imperialviolet.org 650-283-9641
More information about the Libraries
mailing list