Merging changes to volatile bitfield structs
Phil Endecott
spam_from_gcc_help_2@chezphil.org
Fri Oct 19 11:33:00 GMT 2007
John Love-Jensen wrote:
> Hi Phil,
>
>> Can anyone share their preferred approach to this sort of problem?
>
> Reg workingReg = reg;
> workingReg.a = 0;
> workingReg.b = 0;
> workingReg.c = 0;
> reg = workingReg;
I'm having trouble working out the necessary casting:
struct S {
unsigned a : 1;
unsigned b : 31;
};
volatile S s;
void f() {
S x;
x.a = 0;
x.b = 0;
s = x;
}
This fails to compile with g++:
$ g++ -W -Wall -c /tmp/voltest.cc
/tmp/voltest.cc: In function âÂÂvoid f()âÂÂ:
/tmp/voltest.cc:12: error: passing âÂÂvolatile Sâ as âÂÂthisâ argument of
âÂÂS& S::operator=(const S&)â discards qualifiers
It does compile as C, if I replace 'S' with 'struct S'. I have tried
various casts but haven't yet found the right one. Any ideas anyone?
Thanks,
Phil.
More information about the Gcc-help
mailing list