From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2002-11-24 13:27:42


>From: "Pavol Droba" <droba_at_[hidden]>
>
> The prerequisite I haven't mentioned is that if you wan to use a structure
to
> map to such a buffer, it has to have 1 byte aligmnent. Most of the
compilers
> allow this kind of specification with pragmas.
>
> Reinterpret-cast could be avoided like this:
>
> template< typename T >
> inline T* offset_cast( void* p, unsigned int offset=0 )
> {
> return static_cast<T*>(
> static_cast< void* >( static_cast<unsigned char*> p )+offset )
> );
> }

Yes, but that wouldn't make it any more safe, as it would still depend on
the alignment requirements, etc. that you mention.

Regards,

Terje