yep. As you say. The macros evaluate to the same code on AVR, CM0, and CM4. (all gcc, so that's not really surprising.)CM4 ends up using the "bit field extract" instruction, which is pretty nice.
here's code that should be pretty platform-independent:#include <stdint.h>
volatile uint8_t PORTB;
#define BIT_GET(p,m) ( ((p) & (BIT(m))) != 0 )
#define BIT(x) (0x01 << (x))
#define BIT_GET1(p,m) ((((uint8_t)p)>>((uint8_t)m)) & (uint8_t)1)
bool get_b3() {
return BIT_GET(PORTB, 3);
}
bool get1_b3() {
return BIT_GET1(PORTB, 3);
}
bool get_bv(uint8_t b) {
return BIT_GET(PORTB,b);
}
bool get1_bv(uint8_t b) {
return BIT_GET1(PORTB,b);
}
int main() {}
extern "C" { void _exit(int c) {while(1);} }