c++ - 警告 665 : Unparenthesized parameter 2 in macro 'SET_RECORD' is passed an expression

标签 c++ lint

这是我的代码库的一部分......
因为在 MACRO 调用中缩进/分组变量以避免 lint 警告很困惑
代码:

 enum baseId{
    ADDRESS_ID = 0,
    ML_ID
    };
 struct strAddress{
        uint8   Address[6];
    };
 struct strCam{
        FLOAT         currXmm;
        FLOAT         currYmm;
    };
#define SET_RECORD(recordid, bufferptr, type)     {               \
RecordReturnType           status;                        \
RecordManager<type> sampleRecord;                     \
validate(bufferptr != NULL);                          \
status = sampleRecord.SetRecord(recordid, *(type *) (const_cast<void *>(bufferptr))\
         );                           \
validate(status == E_OK);                         \
}

bool fun(const uint8 *diagData){
    bool ret ;
    strAddress tempMac;
    memcpy(tempMac.Address, diagData,sizeof(strAddress));
    SET_RECORD((uint32)ADDRESS_ID,(const void *) &tempMac,strAddress); //line
        ret = TRUE;             
    }

Warning 665: Unparenthesized parameter 2 in macro 'SET_RECORD' is passed an expression

Comment//Line 是这个警告出现的地方......我尝试了不同的方式,将括号放在第二个变量上,但警告仍然存在......

最佳答案

显然,Lint 会警告您宏的第 4 行 validate(bufferptr != NULL);。如果 bufferptr 绑定(bind)到包含优先级低于 != 的运算符的表达式,宏将扩展为您可能意想不到的内容:

SET_RECORD(x, condition ? thisbuf : thatbuf, y) 扩展为:validate(condition ? thisbuf : thatbuf != NULL); 这意味着 validate (条件?thisbuf:(thatbuf!= NULL));

重写该行:validate((bufferptr) != NULL);

关于c++ - 警告 665 : Unparenthesized parameter 2 in macro 'SET_RECORD' is passed an expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21702222/

相关文章:

sass - 让 scss-lint 忽略特定行

javascript - 为什么 "setter is defined without getter"是 JSHint 错误?

c++ - 使用基于数组的列表 c++ 合并 2 个数组

C++线程执行完后还是 `joinable()`?

objective-c - 用于 Objective-C 开发的 lint 检查工具

c - 类似函数的宏, 'REPORT_ERROR',已定义 [MISRA 2012 指令 4.9,咨询]

c++ - 来自环形拓扑的全局最大值,而不是来自 C++ 中的 MPI_REDUCE

c++ - N选K、K-N、K-2N等,递归中递归

c++ - 混合 std::wcout 和 std::cout 会出错,有什么问题吗?

java - 调用 'substring' 是多余的