ceclipsemacrosc51

Invalid use of macro pasting in macro in Eclipse


Hello I have the following problem:

Problem here: Eclipse Bad Character Sequence

Keil Language mapping is using this syntax:

xdata unsigned char Port = 0x1;

Wickenhäuser is slightly different:

xdata unsigned char Port @ 0x1;

So I came to this working solution:

#ifdef __CDT_PARSER__
    xdata unsigned char Port = 0x1;
#else
    //xdata unsigned char Port @ 0x1; //BAD Character Squence encountered: @
    #define AT_ADDRESS(n) @##n //Using this Macro to get around this problem
    xdata unsigned char Port_B AT_ADDRESS(0x1);
#endif

But this solution is not perfect, (doubles writing etc.) and should look like this:

#ifdef __CDT_PARSER__ //In Keil I have to define this too, to make use the Keil syntax
    //#define AT_ADDRESS(n) // This works
    #define AT_ADDRESS(n) =##n // Gives error
#else
    #define AT_ADDRESS(n) @##n
#endif

xdata unsigned char Port_B AT_ADDRESS(0x1); // GIVES ERROR: Invalid use of macro pasting in macro AT_ADDRESS

Unfortunately Eclipse flags this: Invalid use of macro pasting in macro AT_ADDRESS


Solution

  • you don't need pasting at this point. Just replace

    #define AT_ADDRESS(n) =##n
    

    by

    #define AT_ADDRESS(n) = n
    

    same goes for the extended C version, both "expanded" examples you're showing have a space character inserted between the address symbol and the actual address so:

    #ifdef __CDT_PARSER__ //In Keil I have to define this too, to make use the Keil syntax
        #define AT_ADDRESS(n) = n
    #else
        #define AT_ADDRESS(n) @ n
    #endif