Subject:
[ruby-ffi] Bit-fields in automatic struct layout?
From:
Simon Chiang
Date:
12/2/09 12:07 PM
To:
ruby-ffi

I'm trying to convert the following struct into an FFI::Struct using
the struct generator:

    struct symbolHashNode
      {
       struct symbolHashNode *next;
       long count;
       int depth;
       unsigned int permanent : 1;
       unsigned int markedEphemeral : 1;
       unsigned int neededSymbol : 1;
       unsigned int bucket : 29;
       char *contents;
      };

My question is, how do I specify the bit-fields?  When I do the naive
thing:

    class SymbolHashNode < FFI::Struct
      @@@
      struct do |s|
        s.name 'struct symbolHashNode'
        s.include 'symbol.h'

        s.field :next, :symbolHashNode
        s.field :count, :long
        s.field :depth, :int
        s.field :permanent, :uint
        s.field :markedEphemeral, :uint
        s.field :neededSymbol, :uint
        s.field :bucket, :uint
        s.field :contents, :string
      end
      @@@
    end

I get errors like:

  attempt to take address of bit-field structure member ‘permanent’
  ‘sizeof’ applied to a bit-field

Thanks!