Struct initialization is largely dependent on the C language standard a particular compiler supports.
VC doesn't allow C structures to be initialized the way I showed (FBSL used to be compiled using GCC). The VC way to define this union should be as follows: (compile as a console app)
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
union {
struct {
unsigned bGiration : 1; // type name: size in bits
unsigned bUseFPS : 1;
unsigned bAnimateLights : 1;
unsigned bRotation : 1;
unsigned bIsLerping : 1;
unsigned bSyncAudio : 1;
unsigned unused : 26; // currently unused
};
unsigned reDraw;
} bFlag = { 0, 1, 0, 1, 0, 1, 0 }; // initialization
printf("flags: %d %d %d %d %d %d, reDraw = %d, evaluates to %s\n", bFlag.bGiration, bFlag.bUseFPS, bFlag.bAnimateLights,
bFlag.bRotation, bFlag.bIsLerping, bFlag.bSyncAudio, bFlag.reDraw, bFlag.reDraw ? "TRUE" : "FALSE");
bFlag.reDraw = 0; // zeroize all bitflags at once
printf("flags: %d %d %d %d %d %d, reDraw = %d, evaluates to %s\n", bFlag.bGiration, bFlag.bUseFPS, bFlag.bAnimateLights,
bFlag.bRotation, bFlag.bIsLerping, bFlag.bSyncAudio, bFlag.reDraw, bFlag.reDraw ? "TRUE" : "FALSE");
return 0;
}
Alternatively, if the compiler supports the C99 standard, it can use what's called Designated Initialization, or selective initialization of members in an arbitrary order:
........
} bFlag = { .bGiration = 0, .bAnimateLights = 0, .bIsLerping = 0,
.bUseFPS = 1, .bRotation = 1, .bSyncAudio = 1 }; // initialization
to the exact same effect.
Elsewhere throughout the code, the bit flags may be assigned, compared, etc. just like any other ordinary struct or union members.
The bFlag{} union may go into the gP structure as any other of its existing member fields.