Write / Read C Doubles in IEEE 754 Interchange Format

So, I am serializing the C data structure for cross-platform use, and I want to make sure that I write my floating-point numbers in a cross-platform manner.

I planned to just do

 char * pos;
 /*...*/
 *((double*) pos) = dataStructureInstance->fieldWithOfTypeDouble;
 pos += sizeof(double);

But I was not sure that the bytes would be written in an array char *in the IEEE 754 interchange format. I was bitten by cross-platform questions before (endian-ness and whatnot). Is there anything I need to do in doubleorder to receive bytes in an exchange format?

+3
source share
1 answer

C IEEE 754 , , double, .

, , IEEE 754, ( , - - !)... , ( , , , 0x12345678 0x12 0x78 ).

( , , , sprintf() strtod(), , , , , 5.2.4.2.2 C99.)

+2

Source: https://habr.com/ru/post/1742527/


All Articles