On Mon, 06 Sep 2010 09:41:15 -0600, Alex Rousskov <[email protected]> wrote: > On 09/06/2010 01:15 AM, Amos Jeffries wrote: >> Inspired from the SuSE patch submitted by Christian. This is what I >> think should be happening with real ptr maths instead of obsolete >> integer math with potential rounding and endian errors. > > >> void >> memNodeWriteComplete(void* d) >> { >> mem_node* n = (mem_node*)(d - _mem_node_data_offset); > > GCC: pointer of type void * used in arithmetic > > > The value of a (pointer + n) expression depends on what pointer is > pointing to. If you want byte-size increments, you have to cast to char*
> or similar. Meh, one cast too many. > > Using ptrdiff_t instead of int is the right thing to do. I do not thing > you need to cast to it in makeMemNodeDataOffset. You may clarify the > intent by writing: > > // calculate data member offset; p is not dereferenced here > mem_node *p = 0; > return reinterpret_cast<char*>(&p->data) - reinterpret_cast<char*>(p); The point of using ptrdiff_t with p==0L is to reduce multiple casting to non-pointer types. Amos
