Data serialization in C?

前端 未结 5 1714
清歌不尽
清歌不尽 2021-01-14 20:50

I have this structure which I want to write to a file:

typedef struct
{
    char* egg;
    unsigned long sausage;
    long bacon;
    double spam;
} order;
<         


        
5条回答
  •  孤街浪徒
    2021-01-14 21:13

    If you are using IEEE-754 why not access the float or double as a unsigned short or unsigned long and save the floating point data as a series of bytes, then re-convert the "specialized" unsigned short or unsigned long back to a float or double on the other side of the transmission ... the bit-data would be preserved, so you should end-up with the same floating point number after transmission.

提交回复
热议问题