How to byteswap a double?
问题 I'm trying to write a byteswap routine for a C++ program running on Win XP. I'm compiling with Visual Studio 2008. This is what I've come up with: int byteswap(int v) // This is good { return _byteswap_ulong(v); } double byteswap(double v) // This doesn't work for some values { union { // This trick is first used in Quake2 source I believe :D __int64 i; double d; } conv; conv.d = v; conv.i = _byteswap_uint64(conv.i); return conv.d; } And a function to test: void testit() { double a, b, c;