(OT), c++ question about bit fields.

Sorry for the OT question, but i have an inquisition about bit fields.

I have this.
struct BoolBit
{
bool Bit7 : 1;
bool Bit6 : 1;
bool Bit5 : 1;
bool Bit4 : 1;
bool Bit3 : 1;
bool Bit2 : 1;
bool Bit1 : 1;
bool Bit0 : 1;
};

is this legal?
struct BoolBit
{
bool Bit[8] : 1;
}

Originally posted by LostInTheWoods:
is this legal?
struct BoolBit
{
bool Bit[8] : 1;
}

Nop, as you cannot get a pointer on each element. Table element must be accessible through pointers (as a table is just a pointer on a chunk of allocated memory).

Originally posted by LostInTheWoods:
Sorry for the OT question, but i have an inquisition about bit fields.

Even in plain C, bitfields should be avoided whenever possible, mainly for packing reasons. You don’t know how your compiler will “optimize” that structure. Many compilers introduce non-standard __packed-like pragmas or attributes to deal with that, but using them is not a decent design decision.

BTW, you should ask such questions in a more adequate forum such as the ones at www.flipcode.com, as this one is OpenGL related.

Julien.

For C and C++ programming questions I really like the message board on http://www.cprogramming.com Their boards are split up into many different disscusion topics. Like C, C++, Windows Programming, etc etc. I have always liked that website.

-SirKnight