[英]How can I declare array, as a anonymous struct member (or workaround) in C?
我有一個這樣聲明的結構
typedef struct {
volatile uint8_t B[2][32];
uint8_t RESERVED_0[4032];
volatile uint32_t W[2][32];
uint8_t RESERVED_1[3840];
volatile uint32_t DIR[2];
uint8_t RESERVED_2[120];
volatile uint32_t MASK[2];
uint8_t RESERVED_3[120];
volatile uint32_t PIN[2];
uint8_t RESERVED_4[120];
volatile uint32_t MPIN[2];
uint8_t RESERVED_5[120];
volatile uint32_t SET[2];
uint8_t RESERVED_6[120];
volatile uint32_t CLR[2];
uint8_t RESERVED_7[120];
volatile uint32_t NOT[2];
uint8_t RESERVED_8[120];
volatile uint32_t DIRSET[2];
uint8_t RESERVED_9[120];
volatile uint32_t DIRCLR[2];
uint8_t RESERVED_10[120];
volatile uint32_t DIRNOT[2];
} GPIO_Type;
有沒有辦法將上面的保留空間聲明為匿名? 阿卡。 不對每個未實現的空間使用 RESERVED_1、RESERVED_2 等。
我知道例如在位域上,我們可以這樣做:
struct test {
unsigned: 1;
unsigned: 5;
// etc
};
謝謝,
您可以使用匿名聯合:
typedef struct {
union {
volatile uint8_t B[2][32];
uint8_t ALL_0[4096];
};
union {
volatile uint32_t W[2][32];
uint8_t ALL_1[4096];
};
union {
volatile uint32_t DIR[2];
uint8_t ALL_2[128];
};
union {
volatile uint32_t MASK[2];
uint8_t ALL_3[128];
};
union {
volatile uint32_t PIN[2];
uint8_t ALL_4[128];
};
union {
volatile uint32_t MPIN[2];
uint8_t ALL_5[128];
};
union {
volatile uint32_t SET[2];
uint8_t ALL_6[128];
};
union {
volatile uint32_t CLR[2];
uint8_t ALL_7[128];
};
union {
volatile uint32_t NOT[2];
uint8_t ALL_8[128];
};
union {
volatile uint32_t DIRSET[2];
uint8_t ALL_9[128];
};
union {
volatile uint32_t DIRCLR[2];
uint8_t ALL_10[128];
};
union {
volatile uint32_t DIRNOT[2];
};
} GPIO_Type;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.