Subject:
Re: [ruby-ffi] re: Automatic Struct Layout
From:
Wayne Meissner
Date:
12/17/09 6:41 PM
To:
ruby-ffi@googlegroups.com

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.