Re: [edk2] bitfield structures with Visual Studio?

Subject: Re: [edk2] bitfield structures with Visual Studio?

From: Doug Azzarito <>


Date: 2012-03-20 00:42:59

I applaud your efforts. Here's some good news: If I use #pragma
pack(1), I was able to get a 64-bit field with a field crossing the
32-bit boundary to work on MSVC and GCC on 32 & 64-bit builds, mainly
by removing all use of implementation-dependent types. If you have a
bitfield like:

typedef struct {
    unsigned int field1 : 30;
    unsigned int field2 : 4;
    unsigned int field3 : 30;

You will run into problems, but if you use:

typedef struct {
    UINT64 field1 : 30;
    UINT64 field2 : 4;
    UINT64 field3 : 30;

The only problem you'll have is the warnings from MSVC about a
non-standard type in a bitfield (I'd rather have a warning and have it
work, than have NO warning, but it doesn't work!). I have to #pragma
disable the warning on MSVC, but GCC loves it. My test program has
confirmed that the bits do get put in the right place (ignoring
endian-issues), and the structure is the right size. I would still
strongly suggest a checkbomb after each bitfield definition to at
least check that the structure is the right size. That would alert
someone if they changed the packing, changed a field by mistake, or
tried this on a new tool chain.

On Mon, Mar 19, 2012 at 4:10 PM, Andrew Fish  wrote:
> FYI we are working on making the edk2 =A0bit field usage safer. It curren=
tly works correctly on all the compilers ported to edk2 so far.
> Thanks for your report as now we know fields > 32-bits are a no go.
> Sent from my iPhone

This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here =
edk2-devel mailing list