Chris Frey wrote:
> On Fri, Dec 02, 2005 at 05:58:18AM -0700, Warren Young wrote:
>
>>You haven't covered the floating point case, though. The little-known
>>XDR standard can help here: http://www.faqs.org/rfcs/rfc1832.html There
>>should be some free XDR code out there you can kipe.
>
> I took a look at the RFC, and it appears they use IEEE floating point format
> to store floats and doubles.
Yes. XDR is pretty much a codification of the SPARC data formats, for
use with protocols like NFS and RPC. So, Sun just wants everyone to do
it their way. :)
> This is the same format used in C++, as far as I know.
The IEEE standard allows for different byte ordering. To illustrate:
#include <stdio.h>
int main(void)
{
int i;
double x = 42.42;
unsigned char* p = (unsigned char*)&x;
printf("sizeof x = %d, value = ", sizeof(x));
for (i = 0; i < sizeof(x); ++i) {
printf("%02X ", *p++);
}
puts("");
return 0;
}
Run on an x86 box (Linux with GCC or WinXP with VC++), I get:
sizeof x = 8, value = F6 28 5C 8F C2 35 45 40
Run on a G5 PowerMac (GCC 4), I get:
sizeof x = 8, value = 40 45 35 C2 8F 5C 28 F6