You're viewing a comment by Ben and its responses.

Ben Permalink
January 14, 2010, 10:45

Sorry, that did not work as expected :(

B_SET(x, 31) fails because:
- 1 is int (32-bit)
- x is unsigned long (64-bit)
- (1long->unsigned long will sign
extend the rhs of |=

One fix: use typeof
#define BIT_MASK(x,n) ( ((__typeof((x)))1)
#define B_SET(x,n) ((x)|=BIT_MASK((x),(n)))

In c++ one could use templates.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type first 3 letters of your name: (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.