Subject:
Re: [ruby-ffi] re: Automatic Struct Layout
From:
Jon
Date:
12/18/09 8:13 AM
To:
ruby-ffi@googlegroups.com

On Fri, 18 Dec 2009 10:41:39 +1000
Wayne Meissner <wmeissner@gmail.com> wrote:

> 2009/12/18 rogerdpack <rogerpack2005@gmail.com>:
> > Question.
> > Shouldn't ffi be calculating the offsets automagically for us, since
> > all that is distributed is ruby code, and "automatic struct layout"
> > thence not be necessary?  I would have expected that...
> 
> 
> It does, the wiki just hasn't been updated ... in about a year - so
> feel free to fix it up.
> 
> Basically, to have FFI calculate offsets for you, you drop off the
> offset out of the triplet.
> 
> i.e. instead of
> class Foo < FFI::Struct
>   layout :a, :long, 0, :b, :int, 4
> end
> 
> You would use:
> class Foo < FFI::Struct
>   layout :a, :long, :b, :int
> end
> 
> That will calculate the offset of :b automatically for you, and take
> into account 32bit vs 64bit, minimum alignments, tail padding, etc.

We need a Struct wiki page similar to what jacius did for Enums anyway.

Is there any reason why Wayne shouldn't just delete the automatic struct layout page once the struct page exists?

Jon