C Memory layout question

Soldato
Joined
7 Apr 2004
Posts
4,212
Hi,

With variables like an 8 byte double or 4 byte int, is the memory layout exactly the same across Windows, Linux and OSX assuming the endianness is the same?

Say for example, I copy 8 bytes from a double on Linux into a double on Windows, will it work or explode?

Thanks,

Jack
 
and how do you plan to do that? (not taking the mick here, but if you can explain how you would do that, i think you might answer your questions)

Ok thanks guys, let me give an example of what im doing, I need to save data in double variables (8 bytes) to disk (I know this isnt the best way but its ideal for what im doing), and i need it to work for windows, mac and linux. Is a double 8 bytes on all these OSs, and is the memory encoding IEEE standard?

example of how im doing this: (working fine on linux, havent tested on windows/mac)
Code:
double a = 4;
unsigned char *p = (unsigned char *) &a;

for(int i = 0; i < sizeof(double); i++)
{
      bytes.append(p[i]);
}

Thanks,
Jack
 
Back
Top Bottom