Merging changes to volatile bitfield structs
John (Eljay) Love-Jensen
eljay@adobe.com
Fri Oct 19 19:01:00 GMT 2007
Hi Phil,
Hmmm, try this...
struct S
{
unsigned a : 1;
unsigned b : 31;
};
volatile S s;
void f()
{
S x;
x.a = 0;
x.b = 0;
S& nonvolatile_s = const_cast<S&>(s);
nonvolatile_s = x;
}
If you are using C++ anyway, I strongly recommend avoiding bitfields and do the shifting/masking in accessor/mutator functions yourself. That'll help encapsulation, too.
--Eljay
More information about the Gcc-help
mailing list