That is not that strange considering your "flags'" values: (I noticed after I wrote this that your values were in decimal and not hexadecmial, which is assumed below)
PF_FLAG0 = 1000 = %0001000000000000
PF_FLAG1 = 1001 = %0001000000000001
PF_FLAG2 = 1002 = %0001000000000010
PF_FLAG3 = 1003 = %0001000000000011
When you AND, this is what happens:
Flags = PF_FLAG3 = %0001000000000011 Flags => %0001000000000011& PF_FLAG0 => %0001000000000000-------------------------------= %0001000000000000
The result, as you see, is > 0 and therefor true.
What you really want to do, is to let each flag represent their own bit. Like this:
#define PF_FLAG0 0x0001 // = %0000000000000001#define PF_FLAG1 0x0002 // = %0000000000000010#define PF_FLAG2 0x0004 // = %0000000000000100#define PF_FLAG3 0x0008 // = %0000000000001000#define PF_FLAG4 0x0010 // = %0000000000010000#define PF_FLAG5 0x0020 // = %0000000000100000#define PF_FLAGXX1 0x0800 // = %0000100000000000#define PF_FLAGXX2 0x2000 // = %0010000000000000 // This wayunsigned long flags;flags = PF_FLAG0 | PF_FLAG4 | PF_FLAGXX1;// is this:// 0x0001 = %0000000000000001// 0x0010 = %0000000000010000// OR 0x0800 = %0000100000000000// -----------------------------// = 0x0811 = %0000100000010001 // When you want to check a flag, you do thisif(flags & PF_FLAG4) std::cout << "PF_FLAG4 is set!\n";// Which calculate (flags & PF_FLAG4) like this:// flags = 0x0811 = %0000100000010001// AND PF_FLAG4 = 0x0010 = %0000000000010000// ------------------------------------------// = (result) = 0x0010 = %0000000000010000//// And 0x0010 is, surprise, true.
This is really logical and easy, but it can take a while to "get it".
[edited by - CWizard on January 3, 2003 12:52:06 PM]