I have a uint32 variable for some bit field flag state and an enum for these flags. This variable is passed as argument to some functions by value.
I need to add about 20 more flags to it. What are my best options? Extend it to 64 bits or treat it as an array of 2 32bits?
Extending to 64 bits will lead me to use compiler ‘extensions’, as enum is 32bits wide. But using an array seems to lead to more work.
My code compiles on 32 and 64 bit compilers, and runs on windows, linux and mac.
Thanks in advance.
I would use an STL bitset. Then my enum wouldn’t have to be a power of 2. With normal enumeration, it would just be the index into the bitset. You could also use a
vector<bool>.The chief benefit would be portability since your flag set would now fit in any platform’s normal enum range.
example: