I’ve discovered that the “
[b]_BV()[/b]” macro (located in “
[b]arduino-1.0.x/hardware/tools/avr/lib/avr/include/avr/sfr_defs.h[/b]”) doesn’t work if the bit value is 15 or higher.
The macro is simple:
#define _BV(bit) (1 << (bit))
My theory as to why it fails is that the value shifted (1) is by default an int (i.e. a signed 16 bit number which cannot be larger than +32767). To test my theory, I changed the macro to this…
#define _BV(bit) ((uint64_t) 1 << (bit))
…and ta-daa it works.
My questions are:
- Will this still operate as before (i.e. expanded by the pre-processor and only be a value, not code)?
- Should I use uint64_t, uint32_t or size_t?
- Should I replace the macro with a bunch of pre-defines (like this):
#define _BV(0) 0x0000000000000001 #define _BV(1) 0x0000000000000002 #define _BV(2) 0x0000000000000004 // . . . #define _BV(61) 0x2000000000000000 #define _BV(62) 0x4000000000000000 #define _BV(63) 0x8000000000000000
- Do something else?
- Leave it alone, as is with the flaw?
Any input will be appreciated. Thanks!