As a part of a fairly complex function, I wrote this bit of code:
if( (((int)*(pointer-11 .... ) //It is too long and complex
{
*(pointer++)=*(pointer-12)+1;
}
else
{
*(pointer++)=*(pointer-12);
}
The if part works well, but the else parts works like:
*(pointer++)=*(pointer-11);
When I put the incrementing code separate from the actual line ,
if( .... )
{
*(pointer)=*(pointer-12)+1;
}
else
{
*(pointer)=*(pointer-12);
}
pointer++;
It works perfectly. But code on top should work too, right? Any thoughts?
pointer++or thepointer-12part is evaluated first. It's up to the compiler.pointeron the left hand side of an assignment, then you cannot reference it on the right hand side (and vice versa). If you do, the result will be undefined and could vary from compiler to compiler, or with different optimization levels, or even from one release to another. Just don't do it.*(pointer-12)aspointer[-12], and*(pointer)as just*pointer, or aspointer[0].