[Haskell-cafe] Bit Field Marshalling

Michael D. Adams mdmkolbe at gmail.com
Fri Nov 7 21:42:02 EST 2008

On Fri, Nov 7, 2008 at 3:46 AM, Lutz Donnerhacke <lutz at iks-jena.de> wrote:
> * Michael D. Adams wrote:
>> But as far as I can tell, hsc2hs doesn't support bit
>> fields.  On top of that I'm not sure I can make any safe assumptions
>> about what order the bit fields are packed (LSB or MSB first).
> The only portable way to get access to C defined structures is involving
> a C compiler, either using hsc or a C helper module.

I don't think hsc2hs provides that support natively.  (I would love to
be proven wrong about that.)

However, I think it would be reasonable to extend hsc2hs.  I've
attached a basic draft of an extension that would make hsc2hs support
this.  Basically this extra template file adds #{peek_bit
<type>,<field>} and #{poke_bit <type>,<field>} which present basically
the same interface as #{peek} and #{poke} but specialized with some
extra smarts to support bit-fields.

I probably won't have time to refine this code, but if others find
this code to be useful, feel free to take and use code and maybe we
can get some proper support into hsc2hs someday. *nudge nudge*

Michael D. Adams
adamsmd at cs.indiana.edu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: template-bit-hsc.h
Type: text/x-chdr
Size: 3043 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20081107/07b84751/template-bit-hsc.bin

More information about the Haskell-Cafe mailing list