Re: [Haskell-cafe] Bit Field Marshalling

2008-11-07 Thread Michael D. Adams
On Fri, Nov 7, 2008 at 3:46 AM, Lutz Donnerhacke <[EMAIL PROTECTED]> 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). >

Re: [Haskell-cafe] Bit Field Marshalling

2008-11-07 Thread Dan Weston
> C standard allows padding and reorder of struct entries Almost. The ISO C standard does allow structs padding, but *not* reordering: http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf ISO/IEC 9899:1999 C Standard ยง6.7.2.1.13 "Within a structure object, the non-bit-field members and the

Re: [Haskell-cafe] Bit Field Marshalling

2008-11-07 Thread Lutz Donnerhacke
* 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). C standard allows padding and reorder of struct entries in order to match alignme

Re: [Haskell-cafe] Bit Field Marshalling

2008-11-06 Thread Bulat Ziganshin
Hello Michael, Friday, November 7, 2008, 8:51:46 AM, you wrote: > Have others run into this problem before? What options are there for > working around it? if your goal is to maximize portability and not speed, one option is to make another structure without bit fields, and add C helper functio

[Haskell-cafe] Bit Field Marshalling

2008-11-06 Thread Michael D. Adams
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