Storable tuples and what is 'alignment'?

Glynn Clements glynn.clements at
Tue Aug 6 13:58:28 EDT 2002

Simon Marlow wrote:

> > You also need to allow for any padding which is required to satisfy
> > the alignment constraints of b, e.g.
> > 
> > 	sizeOf (a,b) = sizeOf a + padding (a,b) + sizeOf b
> > 		where padding (a,b) = (alignment b - sizeOf a 
> > `mod` alignment b) `mod` alignment b
> > 
> > >     alignment (a,b) = alignment a + alignment b
> > 
> > The alignment of the overall structure is determined by the alignment
> > of the first element. Subsequent elements are aligned (if necessary)
> > by the addition of padding between elements.
> > 
> > 	alignment (a,_) = alignment a

... except, of course, that you would then need a variable amount of
padding if b's alignment exceeds that of a.

> I think in fact that the aligment of the whole structure should be
> 	alignment (a,b) = alignment a `max` aligment b

Technically, it should be the least common multiple of the components'
alignments. If alignments were guaranteed to be a power of two (as
they invariably are), then "max" would suffice; but I can't find
anything in the documentation which actually *states* that that is the

Glynn Clements <glynn.clements at>

More information about the FFI mailing list