Boost logo

Boost :

From: dherring_at_[hidden]
Date: 2007-11-07 10:41:17

On Fri, 2 Nov 2007, David Abrahams wrote:
> Very perceptive. There are almost no ways to use reinterpret_cast
> portably. If you want to get a char* that traverses the bytes of a
> long, you do it as below:
>>> I think the correct change to silence the type conversion error is
>>> char * first = static_cast<char *>(static_cast<void *>(
>>> const_cast<long*>(& l)));
> Hah, I think it's stylistically distasteful, but at least it's
> correct. I wish that it were properly spelled
> reinterpret_cast<char*>(&l) ;-)

Finally; I'd been looking for the "portable" solution -- and stuck with

Maybe Boost could define a standard char_cast or Do What I Mean dwim_cast?

Something like

template <class T>
inline char * char_cast(T *x)
   return static_cast<char *>(static_cast<void *>(x));

template <class T>
inline T * char_uncast(char *x)
   return static_cast<T *>(static_cast<void *>(x));

- Daniel

Boost list run by bdawes at, gregod at, cpdaniel at, john at