[Vm-dev] Re: FFI crashes VM on Linux (was: Z3950 on OSX: module
yaz3 not found)
Andreas Raab
andreas.raab at gmx.de
Fri Dec 24 16:55:53 UTC 2010
On 12/24/2010 5:27 PM, Igor Stasenko wrote:
> If you using structs, one of the things you need to be aware is struct
> fields memory alignment.
>
> for instance:
>
> struct foo {
> char x;
> char y;
> } bar;
>
> try compile and print:
>
> printf ('%d" ,&bar.y -&bar.x );
>
> depending on compiler's default alignment, it could be 1 or 4 or
> anything else. :)
> This is of course may vary from platform to platform and from compiler
> to compiler.
>
> Not sure if you can specify the struct alignment using FFI package.
You can. The default i.e.,
fields
^#(
(x 'char')
(y 'char')
)
is 1-aligned, to change it to be 4-aligned you can tell the FFI how much
bytes each element in the spec takes, i.e.,
fields
^#(
(x 'char' 4)
(y 'char' 4)
)
More commonly, you would have alignments like this:
fields
^#(
(r 'byte')
(g 'byte')
(b 'byte' 2) "<- align next element on word boundary"
(a 'ulong')
)
Cheers,
- Andreas
More information about the Vm-dev
mailing list