[Haskell-cafe] Bit Field Marshalling

Michael D. Adams mdmkolbe at gmail.com
Fri Nov 7 00:51:46 EST 2008


I'm writing a Storable instance for a data type that marshals to a C
structure that contains bit fields such as the following:

struct Foo {
  short x;
  short y;
  unsigned int a : 1;
  unsigned int b : 1;
  unsigned int c : 1;
  unsigned int d : 1;
  unsigned int reserved : 12;
}

For the "x" and "y" fields I've been using hsc2hs and something like
#{peek Foo, x} to extract the fields.  However, bit fields such as "a"
have me stumped.  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).

Have others run into this problem before?  What options are there for
working around it?

Michael D. Adams
mdmkolbe at gmail.com


More information about the Haskell-Cafe mailing list