I am using MPLABX IDE MCC generated code. At some point inside UART driver, there is the following code for UART state.
typedef union {
struct {
unsigned perr : 1;
unsigned ferr : 1;
unsigned oerr : 1;
unsigned reserved : 5;
};
uint8_t status;
}uart1_status_t;
As far as I can understand there are 2 types inside the union, 1 struct and 1 8-bit unsigned variable. I have 2 questions:
- what is actually ...perr : 1; What is done here? type is not indicated only unsigned is written and what is ":1"? It is not a value given to perr? As I tried this out on a C compiler, I saw these are actually bits of the status variable. perr and ferr are 0th and 1st bits but oerr is 4th? Why?
- The struct does not have an 'instance', so how can I access it? I am confused of this section. Since it is a union, these bits and status variable are stored at the same memory location, hence whenever I try to access status it also means accessing these perr, ferr, oerr values? Is it right?