Bitmask flags are a ubiquitous pattern in C & C++ code. In the ‘old days’, they were typically defined as:

#define FLAGS_NONE 0x0 #define FLAGS_DO_A_THING 0x1 #define FLAGS_DISABLE_A_THING 0x2 #define FLAGS_OPTIONAL_FEATURE 0x4 HRESULT MyFunction ( int flags );

Since C/C++ preprocessor defines tend to have a lot of potential hazards, over time developers have moved to using enum :

enum FLAGS_FOR_MYFUNCTION { FLAGS_NONE = 0x0 , FLAGS_DO_A_THING = 0x1 , FLAGS_DISABLE_A_THING = 0x2 , FLAGS_OPTIONAL_FEATURE = 0x4 }; HRESULT MyFunction ( int flags );

With C++11 you can also provide an underlying type of the enum so you can use unsigned long instead of int without any signed/unsigned mismatch warnings:

enum FLAGS_FOR_MYFUNCTION : unsigned long { FLAGS_NONE = 0x0 , FLAGS_DO_A_THING = 0x1 , FLAGS_DISABLE_A_THING = 0x2 , FLAGS_OPTIONAL_FEATURE = 0x4 }; HRESULT MyFunction ( unsigned long flags );

This still leaves the use of flags ‘loosely typed’ since if you had a second set of (possibly unrelated) flags you can easily write:

HRESULT MyFunction ( FLAGS_DO_A_THING | UNRELATED_FLAGS_FEATURE );