Thread: Unions of the same size and pointers

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I write general purpose code on the board most of the time. My function is far from optimal for this purpose. The good news is you could have it swap two of anything. Whether it is a char being swapped with a char, or an array of 50 floats being swapped with another array of 50 floats.

    Your int values won't necessarily translate across the way you are wanting.

    If you do LOWFIXED20_12.full = MIDFIXED20_12.full instead of copying the fraction to the fraction and the integer to the integer you will end up with the bits that make up those numbers out of whack.

    The integer part of LOWFIXED20_12 is 12bits unlike the MIDFIXED20_12 integer, which is 8 bits. So both the quantity that these numbers can store and the memory locations of them within the structure are physically different.

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    12
    Ah, I see what you are driving at and your function makes more sense to me now.

    Thanks again for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 05-21-2009, 05:47 PM
  2. Changing size of array of pointers
    By carrotcake1029 in forum C Programming
    Replies: 1
    Last Post: 11-15-2008, 10:24 PM
  3. Pointers trouble
    By saahmed in forum C Programming
    Replies: 39
    Last Post: 03-24-2006, 04:08 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM