Re: what is the suggested way to do void * arithmetic ?

From: Terry Lambert <tlambert2_at_mindspring.com>
Date: Fri, 11 Jul 2003 03:03:00 -0700
David Leimbach wrote:
>  I always feel better when I convert void * to char * but that's probably
> because C++ doesn't allow pointer arithmetic on void *'s.  The argument
> being that you don't know the size of what's being pointed to with a void *
> and therefore can't know how far to seek the the pointer to get to the next
> valid address.

C++ is pretty freaking draconian in this regard.  You basically
have to use a dynamic cast, where you would use a cast to void *
and another to some other type * in order to coerce the value.

The main issue is that there are pointer types, and then there
are object types, and coercion between the two is strongly
discouraged in order to get you to use proper inheritance (that's
what Bjarne said, anyway).

I don't know if you can do "normal" coercion with the really
"standard" flags on in the 3.3 compiler; I guess we'll get to
find out soon enough...

-- Terry
Received on Fri Jul 11 2003 - 01:07:27 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:14 UTC