Boost logo

Boost :

From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2007-10-11 08:19:34


First there was a typo:
it should read
     operator T() const
not
     operator T&() const

Zara wrote:
> I may not work for PODs. It depends on the data alignment of the
> compiler, and the data alignment capabilities of the processor.
>
> You are invoking the dreaded devils of Undefined Behaviour!

Of course I want to avoid this, but could you please be more specific?

Is it the
static_cast<T>(*data)

that will cause troubles?

If so why?

Would it be better to use something like

operator T() const
{
     T t = 0;
     for (unsigned n=0; n<sizeof(T); ++n)
     {
         t |= ((T)data[n])<<(8*n);
     }
     return t;
}

Roland aka speedsnail


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