[请求] float number in a data file

sable93

资深人士
VIP
注册
2003-11-11
消息
1,222
荣誉分数
92
声望点数
208
各位DX,

想把一大批float number存到data file里,而这个data file将会有不同platforms access,有什么好的store办法。
不想用asccii存,太慢。
float number representation 有IEEE标准,but byte order makes trouble, especially on Linux, the byte order depends on hardware, not OS.
郁闷ing...
 
Save the byte order information (of the file creator) in the data file
"header". Every reader must check this and decided it will need to do
a swap or not.
 
Thanks a lot.

最初由 shusheng 发布
Save the byte order information (of the file creator) in the data file
"header". Every reader must check this and decided it will need to do
a swap or not.
Probably I will have to dynamically check byte order of the env. that the application is running on, then decide need to swap or not based on BOM in the file.
不爽。。。but seems noway...

Thanks again.
 
Re: Thanks a lot.

最初由 sable93 发布

Probably I will have to dynamically check byte order of the env. that the application is running on, then decide need to swap or not based on BOM in the file.
不爽。。。but seems noway...

Thanks again.

Well, you can't have one binary running on both enddin anyway. You can only have one source. Something like:

代码:
  enddian_from_file = find_out_file_endian(filename);

  if (enddian_from_file == BIG) {
#ifdef _BYTE_ORDER == ENDDIAN_BIG
     swap = 0;
#else
     swap = 1;
#endif
   } else {
#ifdef _BYTE_ORDER == ENDIAN_LITTLE
     swap = 0;
#else
     swap = 1;
#endif
   }
 
I do not know if

#ifdef _BYTE_ORDER == ENDDIAN_BIG

works.
Normally we #define something using platform identifier, like

#ifdef _WIN32
#define _BYTE_ORDER ENDDIAN_LITTLE
#else
....
#endif

However the endian could be different on Linux, I have to find another way to #define _BYTE_ORDER.
 
最初由 sable93 发布
I do not know if

#ifdef _BYTE_ORDER == ENDDIAN_BIG

works.
Normally we #define something using platform identifier, like

#ifdef _WIN32
#define _BYTE_ORDER ENDDIAN_LITTLE
#else
....
#endif

However the endian could be different on Linux, I have to find another way to #define _BYTE_ORDER.

I forgot which header in Linux defined the BYTE_ORDER, something under the /usr/include/sys, do a grep, I think you can find it.
 
Found it

最初由 shusheng 发布


I forgot which header in Linux defined the BYTE_ORDER, something under the /usr/include/sys, do a grep, I think you can find it.

thanks a lot.
:cool:
 
后退
顶部