Win binaries and UNIX
-
-
I wrote a C++ program the I run on a NT machine that writes structures to a binary file. I then move the binary file to a Unxi machine and I can't read the files correctly. I am swaping the bytes, is this all that I need to do? Thanks for ANY help. Jim
Check the byte alignment. It is possible that the data is not written to the offset that you expect. Ant.
-
I wrote a C++ program the I run on a NT machine that writes structures to a binary file. I then move the binary file to a Unxi machine and I can't read the files correctly. I am swaping the bytes, is this all that I need to do? Thanks for ANY help. Jim
It really depends on the architechture of each of the machines -- they might both be Little Endian, Big Endian, or a combination of the two. That is to say, you might not need to swap the bytes at all -- doing so could be what's giving you trouble. If at all possible, try using the
ntohs()
andntohl()
functions to ensure you get your data correctly on any architecture. --Dean -
I wrote a C++ program the I run on a NT machine that writes structures to a binary file. I then move the binary file to a Unxi machine and I can't read the files correctly. I am swaping the bytes, is this all that I need to do? Thanks for ANY help. Jim
Also check the struct packing on both compilers, they need to be the same. MSVC defaults to 8 byte alignment, you can change it with
#pragma pack
--Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- You cannot truly appreciate Dilbert unless you've read it in the original Klingon. -
I wrote a C++ program the I run on a NT machine that writes structures to a binary file. I then move the binary file to a Unxi machine and I can't read the files correctly. I am swaping the bytes, is this all that I need to do? Thanks for ANY help. Jim
Depending on the machine architecture, and that the sizes of similar data types are the same byte length, I have seen issues where machines are not "byte" swapped but are "word" swapped. In those cases, it was every set of two-bytes that needed to be swapped with the next set of two-bytes. This is different than big/little-endian swapping. If you are writing floating point values into the file, check that the NT format and the UNIX format are the same. NT probably uses the IEEE floating point format and some non-PC UNIX machines (and some hardware items) use a DEC format. This means that the meaning of the bits within a 4-byte floating point word are different ... different size mantissa, exponent, placement of sign bit, etc. I have had to re-align floating point bits between machines. Dave "You can say that again." -- Dept. of Redundancy Dept.