what is the suggested way to do void * arithmetic ?

Terry Lambert tlambert2 at mindspring.com
Fri Jul 11 03:07:27 PDT 2003


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


More information about the freebsd-current mailing list