Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   union to array (http://www.go4expert.com/forums/union-to-array-t9426/)

boschow 18Mar2008 13:43

union to array
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,

All times are GMT +5.5. The time now is 05:30.