Skip to main content
NVERZ
Associate
January 15, 2020
Question

## preprocessor directive in STM32 eclipse doesn't work

  • January 15, 2020
  • 2 replies
  • 979 views

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

    This topic has been closed for replies.

    2 replies

    berendi
    Principal
    January 15, 2020

    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
    NVERZAuthor
    Associate
    January 24, 2020

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