这是我的代码库的一部分......
因为在 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/