Martin C. Martin wrote:
>
>
> Robert Bradshaw wrote:
>> On Apr 9, 2008, at 8:25 AM, Martin C. Martin wrote:
>>> Hi,
>>>
>>> There's a potential optimization I mentioned on the Lisp inspired
>>> transforms page, where you could reorder bitfields in order to pack them
>>> most efficiently. Eerily, someone at my job just committed something
>>> that did just that. We have a custom defstruct, called defstruct-bv,
>>> which allows you to specify bit fields. (Lisp doesn't come with
>>> bitfields.) Here's the checkin message:
>>>
> ...
>>
>> I believe in Cython we would just rely on the C compiler to make
>> optimizations of this nature.
>
> That's the point, C prescribes that it *can't* make such optimizations.
> C fields (including bitfields) must appear in memory in the order they
> appear in the source code.
>
> For bit fields, this is an advantage when you're, say, parsing the
> header of some binary file, or writing a device driver. But if you just
> want a struct that stores some data compactly, the C compiler can't help
> you out in that case.
>
> Best,
What about gcc's 'packed' attribute?
`packed'
The `packed' attribute specifies that a variable or structure field
should have the smallest possible alignment--one byte for a
variable, and one bit for a field, unless you specify a larger
value with the `aligned' attribute.
Here is a structure in which the field `x' is packed, so that it
immediately follows `a':
struct foo
{
char a;
int x[2] __attribute__ ((packed));
};
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev