I've found some legacy code that goes wrong, setting file attributes. It looks something like this -
flag1 = 0x0001;
flag2 = 0x0002;
DWORD flags = flag1 | flag2;
//great - flags is 3
DWORD prevValue = 0x0010; //say
//add our new flags to prevValue
DWORD newVal = prevValue | flags;
//newVal is 19
//but now I want to remove those flags from newVal
DWORD backToPrev = newVal & !flags;
//but according to my compiler (vs2012)
//!flags is 0, it can't do the logical NOT on the DWORD
ASSERT (backToPrev); // it's 0, should be 16
Any suggestions for a fix?