6 ms·
Bitfields would be, in theory, safer still: no manual bit-twiddling to begin with and also quite straightforward usage. Unfortunately, they are (and I guess wil
by 8xde0wcNwpslOw 8y ago
Bitfields would be, in theory, safer still: no manual bit-twiddling to begin with and also quite straightforward usage. Unfortunately, they are (and I guess will remain) underspecified as far as portability is concerned.
You can, of course, do something similar with member functions, e.g.
class controller
{
unsigned value;
static constexpr unsigned BTN_A = 0x01;
...
public:
bool a() const { return value & BTN_A; }
void a(bool set) { if (set) value |= BTN_A; else value &= ~BTN_A; }
};
- inetknght 8y agoThis is pretty similar to what I've done in the past