diff options
-rw-r--r-- | include/bitset.h | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/include/bitset.h b/include/bitset.h index c72985e..5fe91dd 100644 --- a/include/bitset.h +++ b/include/bitset.h @@ -3,15 +3,14 @@ #include <limits.h> -#define __MLIB_BITSLOT(x) ((x) / CHAR_BIT) -#define __MLIB_BITMASK(x) (1 << ((x) % CHAR_BIT)) -#define __MLIB_BITIMPL(bs, x, op) ((bs)[__MLIB_BITSLOT(x)] op __MLIB_BITMASK(x)) +#define __MLIB_BITSLOT(x) ((x) / CHAR_BIT) +#define __MLIB_BITMASK(x) (1 << ((x) % CHAR_BIT)) -#define bitset(name, n) unsigned char name[(n + CHAR_BIT - 1) / CHAR_BIT] +#define BITSET(name, n) unsigned char name[(n + CHAR_BIT - 1) / CHAR_BIT] -#define BITCLR(bs, x) __MLIB_BITIMPL(bs, x, &= ~) -#define BITSET(bs, x) __MLIB_BITIMPL(bs, x, |=) -#define BITTOGL(bs, x) __MLIB_BITIMPL(bs, x, ^=) -#define BITTEST(bs, x) (bool)__MLIB_BITIMPL(bs, x, &) +#define CLRBIT(bs, x) ((bs)[__MLIB_BITSLOT(x)] &= ~__MLIB_BITMASK(x)) +#define SETBIT(bs, x) ((bs)[__MLIB_BITSLOT(x)] |= __MLIB_BITMASK(x)) +#define TOGLBIT(bs, x) ((bs)[__MLIB_BITSLOT(x)] ^= __MLIB_BITMASK(x)) +#define TESTBIT(bs, x) ((bool)((bs)[__MLIB_BITSLOT(x)] & __MLIB_BITMASK(x))) #endif /* !MLIB_BITSET_H */ |