|
>>>>> "Viacheslav" == Viacheslav Usov <via.usov@gmail.com> writes:
Viacheslav> Moreover, in C++ union-based type punning is undefined
Viacheslav> behavior, and since the Lua source code intends to be
Viacheslav> consumable as C++, this is a problem that volatile does not
Viacheslav> correctly address, either.
Viacheslav> I believe memcpy() is the only way that would be truly
Viacheslav> portable with all those things considered.
I think you are correct, though I'd be surprised if any C++ compiler did
the wrong thing with union type punning of basic types.
The C++ standard seems to have the same exception for aliasing a value
by way of a char or unsigned char type that C has. So your example has
one more copy than is needed - the bytes can be copied directly from or
to the "double" var without needing the intermediate char buff[].
--
Andrew.