The first struct is anonymous but its sub-fields are not. The second struct is also anonymous but its only field is anonymous also, so you don't have a means to reference it. You must give a name to the bit-field. Better, you could also use a 'char' field instead of the second struct. One more point, 'unsigned' is a 16-bit type, if you want your union to occupy just one byte, declare the fields as 'unsigned char'. Isaac On 18/03/2015 21:24, Josh Koffman wrote: > Hi all, > > I'm trying to define a status register in XC8. I'd like to be able to > reference individual bits, but also be able to say, clear the variable > as a whole. > > I currently have it defined as this: > > typedef union { > struct > { > unsigned ENC1UP :1; > unsigned ENC1DN :1; > unsigned ENC2UP :1; > unsigned ENC2DN :1; > unsigned ENC3UP :1; > unsigned ENC3DN :1; > unsigned ENC4UP :1; > unsigned ENC4DN :1; > }; > struct > { > unsigned :8; > }; > > } EncStatus_t; > > In another part of the code, I define a variable using the typedef EncSta= tus_t. > > In my code, I have two lines that try to write to that variable: > > EncStatus.ENC1DN =3D 1; > EncStatus =3D 0; // Clear encoder status register > > The first line works perfect. The second line throws an error though - > illegal conversion between types - int -> volatile union. > > I understand the basic problem here, but I can't seem to fix it. I've > spent a bunch of time looking at the header file for my processor, to > see how I can write to both PORTB and PORTBbits.RB0 successfully. Near > as I can tell, it's because both of those variables are explicitly > being declared at the same address, not because there's anything fancy > in the union. > > So...is there a way to deal with this when I don't know where the > variable will be assigned? > > To be clear, this isn't a work stopping problem, I'd just like to know > if there's a way to do this that is efficient. After all, I can always > just clear each bit individually. > > Thanks! > > Josh --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .