cancel
Showing results for 
Search instead for 
Did you mean: 

## preprocessor directive in STM32 eclipse doesn't work

NVERZ
Associate II

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

2 REPLIES 2
berendi
Principal

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)

NVERZ
Associate II

Ok! it work... thank's!!