Even better imho... use the standard types in : typedef signed char int8_t; typedef signed int int16_t; typedef signed long int int32_t; typedef unsigned char uint8_t; typedef unsigned int uint16_t; typedef unsigned long int uint32_t; These make it explicit the size of the int you intend to use. C tried=20 to make it so that the compiler could pick for you, to some degree=20 anyway, the size of "int" so you didn't force (or guess) what size would=20 run fastest on whatever computer your code was being compiled for. This=20 is pretty irrelevant nowadays, and usually one cares about the size of=20 an int (for anything low-level or microcontroller-CPU-scale) more than a=20 little more speed. I don't know if you're using floats, but XC8 gives you the choice of=20 24-bit or 32-bit floats. 24-bit pulls in less library code, runs=20 faster, and uses 1 byte less storage than 32-bit, but you'll have to=20 decide the precision vs. (everything else) tradeoff. J Isaac Marino Bavaresco wrote: > 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 EncSt= atus_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 .