
11 Oct
2007
11 Oct
'07
12:19 p.m.
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