Re: Merging changes to volatile bitfield structs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux