This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: bug in GCC or C++ standard ?
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