Storable laws

Sven Panne svenpanne at gmail.com
Sat Dec 16 16:02:23 UTC 2017


2017-12-16 16:45 GMT+01:00 Henning Thielemann <lemming at henning-thielemann.de
>:

> I more think of a custom struct with size 12 bytes consisting of a 64 bit
> and 32 bit word. It must be 8-byte aligned. You would have to align all
> elements at multiples of 8-byte and the address difference between two
> array elements is 16 not 12.
>
> On x86 Linux there would be no problem because a 12 byte struct containing
> a 64 bit word must already be padded to 16 byte. But that's an ABI
> definition and Storable wants to keep independent from that, right?
>

Yes, that's an ABI issue. Once again: Storable is *not* for structs, it
never has been and will never be (because there is no single correct
instance for composite struct-like types). Without any further assumptions,
the gap-less definition is the only one which makes sense. And without
instances for struct-like things, it even makes more sense.

So what you want is an instance of the proposed StorableAMD64 class. Taking
your example: An array without gaps of your 12byte struct would e.g. be
totally OK for OpenGL or a packed AMD64-conformant struct, so base
shouldn't choose one for you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20171216/81fa2ed7/attachment.html>


More information about the Libraries mailing list