Re: Is conversion from T* to void*& safe? by Igor
Igor
Wed Apr 16 16:30:13 CDT 2008
Angel Tsankov <fn42551@fmi.uni-sofia.bg> wrote:
> Is the following use of reinterpret_cast safe:
>
> void f(void*& p);
>
> void g(int* p)
> {
> f(reinterpret_cast<void*&>(p));
> }
>
> If my memory serves me right, the standard says that the convertion
> from T* to void* and back to T* should yield the same pointer value,
> but I do not remember anything about references to pointers.
Your code is essentially equivalent to
f(*reinterpret_cast<void**>(&p));
The behavior is implementation-defined. There is no special case for
this in reinterpret_cast description.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925