it is not possible to have a single macro generate multiple identifiers.
If your compiler allows for anonymous structures & unions, you could use that feature to create what you want, because the member names will be promoted up in scope to the containing non-anonymous block. [I'm not sure if GCC offers this or not, it is non-standard behaviour]
IAR does this with a chain of macros that essentially create the union in place, with the desired names. The union itself is anonymous, thus the bit fields end up being promoted to the global scope.
Code:
#define __BYTEBITS(_NAME,_A,_B,_C,_D,_E,_F,_G,_H) \
unsigned char _NAME ## _ ## _A:1, \
_NAME ## _ ## _B:1, \
_NAME ## _ ## _C:1, \
_NAME ## _ ## _D:1, \
_NAME ## _ ## _E:1, \
_NAME ## _ ## _F:1, \
_NAME ## _ ## _G:1, \
_NAME ## _ ## _H:1;
#define SFR_B_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
__io union { \
unsigned char _NAME; /* The sfrb as 1 byte */ \
struct { /* The sfrb as 8 bits */ \
__BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) \
}; \
} @ _ADDR;
#define SFR_B(_NAME, _ADDR) SFR_B_BITS(_NAME, _ADDR,\
Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
SFR_B(PINF, 0x00) /* Input Pins, Port F */
this is from an old version of IAR, the newer versions do it slightly differently. |