Thread: linux, doubles, and unions

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    75
    Quote Originally Posted by matsp View Post
    But unless the compiler is not doing what all compilers I know of does when it comes to unions and the placement of data in them, the double should live in the first 8 bytes of the union. The fact that the union has other members that are longer doesn't change this.

    --
    Mats
    What I was saying is that by copying the whole union and looking at all the different "views"(the different forms given by the variables you choose to look at) of it, it would have given more insight about the problem. Or maybe not if he didn't know anything at all about byte order problems. In this case you could have seen it by looking at the first 8 bytes alone because it was just a byte order problem, but in a more complex situation(data corruption over the network), the partial copy may have been misleading.

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    12

    Bill

    Actually, I did print out all of the bytes in the union. Every byte past the 8th byte had zeros in it.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    75
    Quote Originally Posted by paraglidersd View Post
    Actually, I did print out all of the bytes in the union. Every byte past the 8th byte had zeros in it.
    Yes, that was to be expected, but I thought you actually tested the union just with the code you showed here. But if you did that, then disregard my comment.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    12

    Foot in mouth

    I owe all of you an apology (though I thank all of you because I learned some things from your posts). As such, I have my foot placed firmly in mouth (or tail, whichever you prefer).

    Turns out that 'htond' and 'ntodh' are not system routines. We had those routines coded up, and subsequently 'ifdef'd out (well, they had #ifdef WIN32). So, once I fixed the ifdef situation, my floats and doubles came out correctly because the byte swapping actually happened.

    Again, I thank all of you for responding and helping me.

    Bill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Double's and floats, i need their bytes.
    By Florian in forum C++ Programming
    Replies: 26
    Last Post: 07-08-2008, 05:42 PM