Invalid use of macro pasting in macro in Eclipse

1.7k Views Asked by At

Hello I have the following problem:

  • IDE: Eclipse Version: 2018-12 (4.10.0) with the Keil C51 plugin (for Language Mapping)
  • Compiler (external): Wickenhäuser uc51

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

2

There are 2 best solutions below

2
On BEST ANSWER

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
1
On

Now I build this improved (with the tips above), working solution.

#ifndef COMPILER_COMPAT_H_
#define COMPILER_COMPAT_H_

#define COMPILER_COMPAT_WICKEN // Comment out for use project in Keil


#ifdef __CDT_PARSER__
#   undef COMPILER_COMPAT_WICKEN
#endif

#ifndef COMPILER_COMPAT_WICKEN
#   ifndef BIT_ADDRESS
#       define BIT_ADDRESS(n) = n
#   endif
#else
#   ifndef BIT_ADDRESS
#       define BIT_ADDRESS(n) @ n
#   endif
#endif


#endif /* COMPILER_COMPAT_H_ */