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

    Feb 22, 2007
    Likes Received:
    Trophy Points:
    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:

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

    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,

Share This Page