2020-01-15 03:08 AM
I use this definition
#define ITEM(A,B,C,D,E,F) (((ulong32)##A## << 25) | ((ulong32)##B## << 20) | ((ulong32)##C## << 15) | ((ulong32)##D## << 10) | ((ulong32)##E## << 5) | ((ulong32)##F##))
that "translate" any switch case block in a constant
switch (index)
{
case ITEM(30,1,0,0,0,0):
instruction...
break;
case ITEM(30,1,1,0,0):
instruction...
break;
case ITEM(30,1,20,0,0):
instruction...
break;
lot of other "case ITEM..break" block
}
so, at compiling time, preprocessor take ITEM parameter and, appling defined macro make a substitution with the CONSTANT NUMBER of macro result.
With another C compliler it work very well, but with my Eclipse 4.6.3 doesn't work and I obtain lot of error, at least one for each "case ITEM...:" block.
Can someone help me?
Thank Nino
2020-01-15 04:32 AM
Did you READ those error messages? What did they tell you?
It is invalid C syntax. The ## preprocessor operator creates tokens by pasting its left and right operands together. The ')' character is a token by itself, ')30' would be an invalid token. Delete the ## nonsense, and place the macro operand in parentheses instead.
#define ITEM(A,B,C,D,E,F) (((uint32_t)(A)<<25u)| ...
I wonder what that another C compiler would do with ITEM(3*10,1,0,0,0,0)
2020-01-24 01:50 AM
Ok! it work... thank's!!