I'm using a macro to compute the size of a bit-field. Would it be possible to use a template?
Code example:
#include <stdio.h>
/*!
@param reg a bit-fields structure
@param field name of one of the fields in 'reg'
*/
#define GET_FIELD_MAX(reg, field) ({ \
decltype(reg) r; \
r.field = ~0UL; \
r.field; })
struct A {
unsigned a : 3;
unsigned b : 4;
};
int main()
{
A x;
printf("b size = %d", GET_FIELD_MAX(x, b));
}
Output:
b size = 15