I'm trying to assign a variable using the result of a function.
MAT2 _m_pow2(const MAT2 A, int p, MAT2 tmp)
{
MAT2 out;
int it_cnt, k, max_bit;
#define Z(k) (((k) & 1) ? tmp : out)
out = m_get2(A.m, A.n);
tmp = m_get2(A.m, A.n);
if(p == 0)
out = m_ident2(out);
else if(p > 0)
{
it_cnt = 1;
for(max_bit = 0; ; max_bit++)
if((p >> (max_bit+1)) == 0)
break;
tmp = m_copy2(A);
for(k = 0; k < max_bit; k++)
{
Z(it_cnt+1) = m_mlt2(Z(it_cnt), Z(it_cnt));
it_cnt++;
if(p & (1 << (max_bit-1)))
{
Z(it_cnt+1) = m_mlt2(A, Z(it_cnt));
it_cnt++;
}
p <<= 1;
}
if(it_cnt & 1)
out = m_copy2(Z(it_cnt));
}
return out;
#undef Z
}
The function m_mlt2() returns MAT2. I am getting these errors:
error: lvalue required as left operand of assignment
Z(it_cnt+1) = m_mlt2(Z(it_cnt), Z(it_cnt));
and
error: lvalue required as left operand of assignment
Z(it_cnt+1) = m_mlt2(A, Z(it_cnt));
What am I doing wrong? If it needs more detais, please, feel free to ask. Thanks in advance!
P.S. I know I will get downvotes, I tried to do my best formulating this question.
Z
macro does not generate an lvalue, as the error says.#define Z(k) (((k) & 1) ? &tmp : &out)
...*Z(it_cnt+1) = m_mlt2(A, *Z(it_cnt));
it should compile and sadly win the wrath of other programmers.