returnBitValue(myArray, i*j)
Expands to
(name[(i*j/LIMIT)+1] & (1<<(i*j%LIMIT))) ? 1 : 0
Which is different from what you probably intended:
(name[((i*j)/LIMIT)+1] & (1<<((i*j)%LIMIT))) ? 1 : 0
So at the very least you will need to add parantheses around index
in the macro expansion. But it will still break if you try to do something like
returnBitValue(myArray, i++)
so better don't use macros at all if you can avoid it (although I understand that it seems to be a specific condition to not use functions in this case).
You also have some more problems in setBitValue
:
(name[((index)/LIMIT)+1] = (value)) ? (... |= ...) : (... &= ...)
You probably meant
name[((index)/LIMIT)+1] = (value) ? (... | ...) : (... & ...)
You also have a potential integer overflow: 1
has type int
, but you treat it as a long
. Use 1L
instead.