bug in GCC or C++ standard ?

Andrew Pinski pinskia@gmail.com
Thu Nov 13 22:46:00 GMT 2008


On Wed, Nov 12, 2008 at 2:10 PM, Lawrence Crowl <crowl@google.com> wrote:
>
> Now would be a good time to mention Google's bit_cast<>.

And here is a simple portable implementation (still implementation
defined really) of that:
#include <cstring>
template<typename to, typename from> to bit_cast(from a)
{
 int notthesamesize[sizeof(from) == sizeof(to)?1:-1];
 to b;
 std::memcpy (&b, &a, sizeof(from));
 return b;
}


Thanks,
Andrew Pinski



More information about the Gcc mailing list