Thanks Stephen and Carter. I think what was happening is that CGFloat is either a float or a double depending on whether or not the target is 64bit. This was making the alignment not what I expected. My trick is just to have an intermediate struct that I can depend on gets fed into haskell. Now I'm working on marshalling arrays of structs.


On Fri, Jan 3, 2014 at 3:27 PM, Stephen Blackheath [to GHC-iPhone] <likeliest.complexions.stephen@blacksapphire.com> wrote:

Schell,

Take a look at my Storable instance for SockAddrBTH here:

https://github.com/the-real-blackh/simple-bluetooth/blob/master/Network/Bluetooth/Device.hsc

Using .hsc files gives you get the offset into the structure like this:

  p `plusPtr` (#const offsetof(struct sockaddr_rc, rc_bdaddr))

#include <stddef.h> to give you offsetof.

Quite a useful trick.


Steve

On 04/01/14 08:41, Schell Scivally wrote:
> I'm having a hard time unmarshalling a c struct into a haskell record.
> Does anyone have a good link that talks about unmarshalling nested c
> structs? Is this common or should I just forget about it?
>
> --
> Schell Scivally
> http://blog.efnx.com
> http://github.com/schell
> http://twitter.com/schellsan
>
>
> _______________________________________________
> iPhone mailing list
> iPhone@haskell.org
> http://www.haskell.org/mailman/listinfo/iphone
>
_______________________________________________
iPhone mailing list
iPhone@haskell.org
http://www.haskell.org/mailman/listinfo/iphone



--
Schell Scivally
http://blog.efnx.com
http://github.com/schell
http://twitter.com/schellsan