Boost logo

Boost :

From: Pavol Droba (droba_at_[hidden])
Date: 2002-11-24 15:00:54


On Sun, Nov 24, 2002 at 07:27:42PM +0100, Terje Sletteb? wrote:
> >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.
>

Alignment dependency is quite natural here. I'm talking about analysis of binary data.
I don't see a way how to map a c-like structure onto binary data if you don't know what's
the bineary representation of the structure and if if does not match the required
pattern.

Well there is one, but it would need far more complicated framework.

Pavol


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk