Problem of two consecutive ++operators , always works the second ?


I'm passing values of an array by pointer to a funtcion, and as you can see I use ++prefix to increase the index,
1
2
3
4
5
w_math->Visual_cent(&w3d_p3d_af[++w3d_p3d],&w3d_p3d_af[++w3d_p3d]) 

w_math->Visual_cent(*x,*y) 
*x=10;
*y=20;


I dont know what is happen but I have the values
0, 20
That is , the first value never receives data .
Are this a compile error ? Have I to change by w3d_p3d+1, wp3d+2 ?
Thanks

Last edited on
closed account (iLUjLyTq)
Try changing pre-incrementation to post-incrementation:

w_math->Visual_cent(&w3d_p3d_af[w3d_p3d++],&w3d_p3d_af[w3d_p3d++])
The problem is you are incrementing the variable twice between two sequence points. That results in the weird behavior you are seeing.
The order in which parameters are evaluated is not defined by the C++ standard, so it could be any order. Usually it's right to left, but you should never rely on undefined behavior.
Topic archived. No new replies allowed.