Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Win binaries and UNIX

Win binaries and UNIX

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jimNLX
    wrote on last edited by
    #1

    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

    A D M D 4 Replies Last reply
    0
    • J jimNLX

      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

      A Offline
      A Offline
      Antony M Kancidrowski
      wrote on last edited by
      #2

      Check the byte alignment. It is possible that the data is not written to the offset that you expect. Ant.

      1 Reply Last reply
      0
      • J jimNLX

        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

        D Offline
        D Offline
        Dean Goodman
        wrote on last edited by
        #3

        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() and ntohl() functions to ensure you get your data correctly on any architecture. --Dean

        1 Reply Last reply
        0
        • J jimNLX

          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

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • J jimNLX

            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

            D Offline
            D Offline
            David Chamberlain
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups