【问题标题】:How to make clang not substitute #define macro如何使clang不能替代#define宏
【发布时间】:2019-10-13 02:31:45
【问题描述】:

我在指针result 上调用Success 方法,但是clang 用X11.h 替换了宏Success

/home/dev/common/src/flutter_orwell_plugin.cc:42:10: error: expected unqualified-id
        result->Success(&response);                                     
                ^                                                       
/usr/include/X11/X.h:350:21: note: expanded from macro 'Success'        
#define Success            0    /* everything's okay */

我无法更改名称“Success”,它来自库。为什么会这样?

【问题讨论】:

  • 我相信这是我们为宏使用不同的命名约定而不是函数名称的原因之一。函数名是来自库还是宏?
  • #undef它,或者重命名函数
  • 另一种避免该问题的方法是拆分文件,这样您就不需要同时包含来自同一个源文件的两个文件。

标签: c++ clang


【解决方案1】:

您可以使用undef 指令来删除先前定义的宏。例如:

#undef Success
return result->Success(&response);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-26
    • 2015-01-13
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-30
    相关资源
    最近更新 更多