This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Merging changes to volatile bitfield structs


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.





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]