[cairo] Using bit fields a bit more in cairo

Hans Breuer hans at breuer.org
Thu Dec 21 01:03:38 PST 2006

On 20.12.2006 17:12, Jim Gettys wrote:
> Carl,
> I'd do a bit more homework on this topic before going the bitfield
> direction in API's, though in many ways, I agree with most of the points
> you've made.
> There are two places you can get bit (if you don't mind the pun):
>   o wire protocols (probably not applicable to this circumstance), where
>     you have to be careful about alignment and byte ordering.
>   o differing compilers on the same system.
> Last I knew (maybe more recent C standards have "fixed" this), C did not
> define which bits get used to represent a bit field in a larger object.
AFAIK it still does not, neither does C++.

> The issue is, if one compiler does it one way and another does it
> differently on the same platform, you can lose when code from different
> compilers get mixed (not all platforms only use gcc...).
This used to be a bigger problem before gcc on win32 learnt how the M$
compiler does it. It almost certainly will bite again, if yet another
compiler (Openwatcom, BCC, ...) is thrown in the mix, but there are other
problems like calling conventions and general struct packing rules anyway.

To overcome the problem gtk+/configure.in explicit requests compatible
behaviour from gcc, see:

# Ensure MSVC-compatible struct packing convention is used when
# compiling for Win32 with gcc.
# What flag to depends on gcc version: gcc3 uses "-mms-bitfields", while
# gcc2 uses "-fnative-struct".

Apparently Pango does not have this, but even if it did, it may not cover
all the possible bug variants (see below).

> And I don't know if ABI conventions on platforms are clear on this
> point.
At least I wasn't able to find much documentation about it, except for 64
bit platforms.

> If someone has data on the current state of C compilers cross platform,
> now is the time to speak up.
>                         Regards,
>                                   - Jim
> On Tue, 2006-12-19 at 18:23 -0500, Behdad Esfahbod wrote:
>> All agreed.  I don't see any reason not to use bitfields.  We use them
>> in Pango in public api and never had any problem that I know of.
Just remember (thanks for reopening):
where adding a bitfield on gcc/Linux did not change the ABI there, but
broke ABI on msvc/win32. This was with only one compiler per platform, so
even the selected msvc-gcc compatibility would not have avoided it. But it
could be a good test how far this compatibility reaches. (Did the original
change ABI also beak gcc/win32 with -mms-bitfileds?)


-------- Hans "at" Breuer "dot" Org -----------
Tell me what you need, and I'll tell you how to
get along without it.                -- Dilbert

More information about the cairo mailing list