T
throwback1986
Hi,
An API requires that buffers be powers of 2, so I borrowed a macro
from Sean Anderson bit hacks page for the following macro:
#define IS_NOT_POWER_OF_2(v) (((v) & ((v) - 1)) && (v))
I then test the condition:
#if IS_NOT_POWER_OF_2(31)
#error "Oops"
#endif
And this works perfectly. However when I try something closer to my
intended use:
#if IS_NOT_POWER_OF_2(sizeof(int))
#error "Oops"
#endif
gcc 3.4.4 reports:
main.cpp:31:34: missing binary operator before token "("
cpp doesn't shed any light, and I have confirmed that my test fails to
compile on other compilers, as well. What am I missing?
Thanks
An API requires that buffers be powers of 2, so I borrowed a macro
from Sean Anderson bit hacks page for the following macro:
#define IS_NOT_POWER_OF_2(v) (((v) & ((v) - 1)) && (v))
I then test the condition:
#if IS_NOT_POWER_OF_2(31)
#error "Oops"
#endif
And this works perfectly. However when I try something closer to my
intended use:
#if IS_NOT_POWER_OF_2(sizeof(int))
#error "Oops"
#endif
gcc 3.4.4 reports:
main.cpp:31:34: missing binary operator before token "("
cpp doesn't shed any light, and I have confirmed that my test fails to
compile on other compilers, as well. What am I missing?
Thanks