Re: Drawing a point in a pixbuf.



Jose Hevia wrote to Magnus Myrefors:
         ->  *p++ = 0xff;

Please don't do that, different compilers will interpret this differently.
I understand this means:

+increment *p (the content of the variable p points to)
+store 0xff in *p

OR

+increment p
+store 0xff in *p

None of the above is correct.

"*p++ = 0xff;" means:
       store 0xff in the location pointed to by p,
       THEN increment p.

This is standard C precedence of operator stuff. The '++' binds more tightly to 'p' than the unary '*' does, so it applies to the pointer itself, not the value stored in that location. However, because '++' is a suffix the value of 'p++' is p, not p+1, so the 0xff value is stored at p, not p+1.

All C compilers should interpret that line of code in the same manner.

But you're right with the general principle that if you find it confusing, you should rewrite it in a clearer manner.

Richard.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]