I'm beginning to learn programming embedded C micro-controllers and want to do something that would make my life easier. Usually when dealing with bit masking everybody uses stuff like:
char a = (1 << 3) | (1 << 1) | (1 << 5);
I want to use a macro for something like this. For just one mask I can simply define this macro:
#define M(n) (1 << (n))
Nothing fancy. The problem is that I cannot come with a good solution that would allow me to type:
a = MM( 3, 1, 5 );
or at least a = MM( 3, 3, 1, 5 );
(where the first 3
is the number of arguments)
instead of a = M(3) | M(1) | M(5);
I came up with a solution which implied using functions with multiple arguments but it's really bugging me that I cannot do it using a macro.