I have an array of unsigned 16-bit integers:
static uint16_t dataArray[7];
The bits of the 7th element of the array represents some kind of status. I want to get and set the values of this status in an easy way, without bit shifting and without having to copy a new value to the array every time the status changes. So I created a union with a struct, and a pointer:
typedef struct {
unsigned statusCode : 4;
unsigned errorCode : 4;
unsigned outputEnabled : 1;
unsigned currentClip : 1;
unsigned : 6;
} SupplyStruct_t;
typedef union {
SupplyStruct_t s;
uint16_t value;
} SupplyStatus_t;
static SupplyStatus_t * status;
My initialisation routine wants the status pointer to point to the 7th element of the array, so I tried:
status = &(dataArray[6]);
Although this works, I get a warning: assignment from incompatible pointer type
Is there a better way to do this? I cannot change the array, but I am free to change the structure, the union or the pointer to the array..