Re: building and analysing C structs with Storable
Henning Thielemann <[email protected]> Sun, 14 Oct 2007 21:19:24 +0200 (CEST)
| Newsgroups | gmane.comp.lang.haskell.libraries,gmane.comp.lang.haskell.ffi |
|---|---|
| Message-ID | <[email protected]> |
On Sat, 13 Oct 2007, Adam Langley wrote: > On 10/13/07, Henning Thielemann <[email protected]> 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 I do not quite see the need for an extra tool. I thought it must be possible to ship a Haskell compiler with modules that depend on the system's C compiler, just like the modules that are implemented differently for Windows and Unix. Such modules could provide the functionality to create and inspect C structs for exchange with system libraries.