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.最初由 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.
最初由 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.
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
}
最初由 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.