Im trying to write a few simple macros to simplify the task of setting and clearing bits which should be a simple task however I cant seem to get them to work correctly.
#define SET_BIT(p,n) ((p) |= (1 << (n)))
#define CLR_BIT(p,n) ((p) &= (~(1) << (n)))
Try
#define CLR_BIT(p,n) ((p) &= ~((1) << (n)))
However for various reasons of general macro evil I would advise not using a macro. Use an inline function and pass by reference, something like this:
static inline void set_bit(long *x, int bitNum) {
*x |= (1L << bitNum);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With