[MacRuby-devel] Bitfields and arrays in structures

Vincent Isambart vincent.isambart at gmail.com
Tue Jan 5 21:29:20 PST 2010


> Any idea on how to handle C bitfields?

I don't know exactly how the compiler packs bitfields (especially it
seems to depend on the compiler and the platform). Anyway for MacRuby
we only officially support two platforms : MacOS X (>= 10.5) on i386
and x86_64, both being of course little endian. You do not need to
care about other environments. Even if you make something that only
works on one of those platforms it would be very nice. I'm sure we
could find someone that can adapt it to work on the other.

You first need to check how the compiler does its packing.
For instance creating something like
union {
  struct {
    int a : 3;
    unsigned int b : 4;
  }
  char data[10];
}
assigning different values to the values in the struct, trying with
data in the struct of multiple sizes (having something of less than 1
byte, less than 2, less than 4...), and looking the data's size and
how the data is represented in memory.
Then do some automatic tests to test the desired behavior, like what
we do currently in ./spec/macruby/language/objc_method_spec.rb
And then do the coding, at least if you're developing tests first.
Anyway having tests is pretty important.

Cheers


More information about the MacRuby-devel mailing list