I have a struct defined as:
#pragma pack(push,1)
typedef struct {
uint8_t source_ID;
uint8_t dest_ID;
union {
uint8_t node_ID;
struct {
unsigned int dest : 4;
unsigned int source : 4;
};
};
} IDs_t;
#pragma pack(pop)
When I declare one of these structs I do the following:
IDs_t IDs = {
.source_ID = TWI,
.dest_ID = APP,
.source = INTERNAL,
.dest = LISTENER,
};
The values I'm setting them equal to are #define
values.
When I compile the code it works, no errors.
If I declare one of the structs like this:
IDs_t IDs = {
.source_ID = TWI,
.dest_ID = APP,
.dest = LISTENER,
.source = INTERNAL,
};
Then I get the following errors:
501:9: error: missing initializer [-Werror=missing-field-initializers] 501:9: error: (near initialization for 'IDs...source') [-Werror=missing-field-initializers]
When all I did was reorder the element declarations. Is this not allowed? I can't seem to find the answer, but I have a suspicion. My suspicion is that since I am using an ARM core from ST, the memory is in little endian format. Which means that the source
element is the LSB of the node_ID
element. Therefore I must declare the LSB first and then the MSB, which would be the dest
element.
Is my suspicion correct? Or is there another reason for these errors?