Reputation: 27
#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;
}
When I try to compile, I get this error,related to increment operand
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
Anyone please shed light on this???
Upvotes: 1
Views: 188
Reputation: 5612
Macros will essentially perform a text replacement that happens via the pre-processor.
The macro will turn your code into something like 1++
and 5++
. These are integer literals, which means the compiler marks them as 'pure' rvalues (prvalues). prvalues are not the same as l-values
Upvotes: 3
Reputation: 754160
Given that you apply a ++
operator to the pos
argument, you cannot pass a constant like 1 or 5 as the third argument to the macro. Any compiler that let you do that would be erroneous.
Upvotes: 2