宏在gcc中给出了问题

时间:2013-10-17 04:04:54

标签: c++ macros byte

#include<vector>
#include<stdint.h>
#define RAM_M_V_INSERT_T32(vec,Long,pos) \
vec.at(pos)=(((tU8)((Long) >> 24)) & 0xFF); \
pos++;\
vec.at(pos)=(((tU8)((Long) >> 16)) & 0xFF); \
pos++;\
vec.at(pos)=(((tU8)((Long) >> 8)) & 0xFF); \
pos++;\
vec.at(pos)=(((tU8)((Long))) & 0xFF);

int main()
{  
std::vector<char> c8vBuf;
c8vBuf.at(0)=(char)SYSTEM_U32_SHUTDOWN_CPU_WATCHDOG;
RAM_M_V_INSERT_T32(c8vBuf, (_u32WdtCount - 1),1);
RAM_M_V_INSERT_T32(c8vBuf, _u32WdtCount,5);
return 0;
}

当我尝试编译时,我收到此错误,与增量操作数相关

cstr.cpp:19:3: error: lvalue required as increment operand
cstr.cpp:19:3: error: lvalue required as increment operand
cstr.cpp:19:3: error: lvalue required as increment operand
cstr.cpp:20:3: error: lvalue required as increment operand
cstr.cpp:20:3: error: lvalue required as increment operand
cstr.cpp:20:3: error: lvalue required as increment operand

任何人都可以了解这个???

2 个答案:

答案 0 :(得分:3)

宏将基本上通过预处理器执行文本替换。

宏会将您的代码转换为1++5++。这些是整数文字,这意味着编译器将它们标记为“纯”rvalues(prvalues)。 pr值与l值不同

答案 1 :(得分:2)

假设您将++运算符应用于pos参数,则不能将常量(如1或5)作为宏的第三个参数传递。任何让你这样做的编译器都是错误的。