Please help me understand the meaning of this code. I have seen this kind of usage for the first time
typedef enum {
E_1_DEFAULT = 0,
E_1_1,
E_1_2,
E_1_3,
E_1_4,
E_1_5,
E_1_255 = 255 //needs at least 8Bit
} APPLICATION_ENUM_1;
typedef enum {
E_2_DEFAULT = 0,
E_2_1,
E_2_2,
E_2_3 //needs at least 2Bit
} APPLICATION_ENUM_2;
typedef enum {
E_3_DEFAULT = 0,
E_3_1,
E_3_2,
E_3_3,
E_3_4,
E_3_5,
E_3_666 = 666 //needs at least 10Bit
} APPLICATION_ENUM_3;
typedef struct {
APPLICATION_ENUM_3 var3:10; // 10Bit
APPLICATION_ENUM_1 var1:8; // 18Bit
APPLICATION_ENUM_2 var2:2; // 20Bit
uint8 unnused_1:4; // fill up the last whole byte -> 24Bit = 3byte
} APPLICATION_RAM;;
According to the C++ standard
Now lets look at the first definition
definition
E_1_255 = 255ensures that all values from0 to 255can be represented by this enum type and you need at least 8bits to represent all values from0 to 255The above struct is using a seldom used bitfield construct. Basically declaring the
APPLICATION_RAMas a struct that has avar3member that is 10 bitsvar1member that is 8 bitsvar2member that is 2 bitsunnused_1member that is 4 bits