I've seen others use Bitwise-OR to combine flags before:
#define RUN 0x01
#define JUMP 0x02
#define SHOOT 0x04
const byte madPerson = RUN | JUMP | SHOOT;
That's also the way I do it.
But I've also seen some (not as many) combine flags using addition:
#define RUN 0x01
#define JUMP 0x02
#define SHOOT 0x04
const byte madPerson = RUN + JUMP + SHOOT;
Which one is more "readable"? (Which one do you think more people will recognize?) What is the "standard" way to do it? Which one do you prefer?
1<<0
,1<<1
,1<<2
, and so on. When you have many flags, it becomes more readable, more maintainable, less error-prone. For instance, if you are packing all 64 bits of a 64 bit int, you really want to avoid typos :) How you represent1
is also important. For a 64 bit integer in VS2010 I think it is1UI64
, or something like that. Using a wrong type might bite you.