On Wed, Jun 3, 2009 at 1:11 AM, Isaac Marino Bavaresco < isaacbavaresco@yahoo.com.br> wrote: > > These things are perfect if you are always use pointers to byte size > types > > (like char for example). In C the +n means +n*sizeof(m). For example if > you > > have a pointer to int32 to mem location 100 and want to address of the > 4th > > element in the array, you say *m+n = *100+(4*4) = 116. Now if you say > *n+m = > > *4+100 it is only 104 or if you say *4+(4*100) then again that's wrong. > > > > Tamas > > > > No, not true. The compiler knows the size of the object pointed to by > the pointer and scales the index so you access the correct element. > > long *p, n; > n = *(p+10) // Accesses the 11th element of the array, not the middle of > the 3rd element. > Yep, I know this. What I was confused was about n = *(10+p) -- I thought the compiler gets the number 10, treats as an integer and silently converts as a pointer and then gets the p and casts as an integer and as a results overall messes up the size. But now it is clear. What is more confusing is n = 10[p] which is still correctly calculated. Thanks, Tamas -- http://www.mcuhobby.com -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist