1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

union to array

Discussion in 'C' started by boschow, Mar 18, 2008.

  1. boschow

    boschow New Member

    Joined:
    Feb 22, 2007
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    0
    Hi all,

    what happens if i try to put an union to array. I want to have two ways of programing the code one way is to use (bits) the other to use intigers. Let me explain in the followinf example:

    Code:
    typedef union
    {
         struct 
         {
             unsinged a1:1;
             unsigned a2:2;
             unsigned a3:3;
             unsigned a4:4;
             unsigned a5:5;
             .
             .
             .
         }bits;
         int ALL;
    }Coils;
    
    Now if i want to make a structure out of this, I would make something like this:

    Code:
    int main()
    {
        ...
        Coils coil;
        coil.ALL   Coils[200]; // now i have 200 int variables?
        coil.bits.a1 = 1; // the other way to program?
    }
    
    What i want to ask you is if I write the program using the second way (coil.bits.a1 = 1;) it will also change the value of the array? Or I must use pointers? If you have any better solution please feel free to share it.

    Thanks and
    best regards,
    BoSCHoW.
     

Share This Page