c++ - How many options can I include in a bit mask? -


in this question pointed out that:

using int [for bit mask] asking trouble

i have been using unsigned char store bitmask flags, occurs me hit low limit since char byte, 8 bits, 8 options in mask?

enum options{  k1=1<<0,  k2=1<<1,   .... through k8  }   unsigned char myoption=k2; 

do need make myoption int or other type example if wish store more 8 possible options (and combinations of options, of course, hence why using bit mask in first place)? what's best type?

#include <stdint.h> 

this defines types fixed sizes not compiler specific.

int16_t = 16 bits

uint16_t = 16 bits unsigned

int32_t = 32 bits

if need more 64 flags should consider ::std::vector<> wayne uroda suggested.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -