Advertisement

Passing Flags to a function...

Started by January 03, 2003 11:34 AM
9 comments, last by MattS423 21 years, 10 months ago
quote: Original post by erjo
Hmm, but he forgot one...
0x1
0x2
0x4
0x8
0xF <--- This one
0x10
0x20
0x40
0x80
0xF0 <--- AAANNNDDDD this one.
15 (0xF, %1111) or 240 (0xF0, %11110000) are not a power of 2, and so cannot be used to represent an individual bit, and so cannot be used as flag values.

MattS423, as others have said, you can only have 32 flags in a long. If you provide 32 flags, you provide a little more than 4 billion combinations.

There probably are several similar macros, but a convinient one to use when defining flag values might be this:
#define FLAG(x) (1 << x) #define PF_FLAG0      FLAG(0)   // Evals to (1 << 0) == 0x01#define PF_FLAG1      FLAG(1)   // Evals to (1 << 1) == 0x02#define PF_FLAG2      FLAG(2)   // Evals to (1 << 2) == 0x04#define PF_FLAG3      FLAG(3)   // Evals to (1 << 3) == 0x08#define PF_FLAG5      FLAG(5)   // Evals to (1 << 5) == 0x20#define PF_FLAG7      FLAG(7)   // Evals to (1 << 7) == 0x80


This topic is closed to new replies.

Advertisement