在 Eclipse 的宏中无效使用宏粘贴

Invalid use of macro pasting in macro in Eclipse

您好,我遇到了以下问题:

此处出现问题:Eclipse 错误字符序列

Keil 语言映射使用此语法:

xdata unsigned char Port = 0x1;

Wickenhäuser 略有不同:

xdata unsigned char Port @ 0x1;

所以我找到了这个可行的解决方案:

#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

但是这个解决方案并不完美,(双写等)应该是这样的:

#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

不幸的是,Eclipse 标记了这一点:在宏中无效使用宏粘贴 AT_ADDRESS

此时您不需要粘贴。只需更换

#define AT_ADDRESS(n) =##n

来自

#define AT_ADDRESS(n) = n

扩展 C 版本也是如此,您显示的两个 "expanded" 示例都在地址符号和实际地址之间插入了一个 space 字符,因此:

#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

现在我构建了这个改进的(使用上面的提示)可行的解决方案。

#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_ */