我应该如何编写代码来举例说明恰好是结构成员的数组的特定数组索引?以下代码给我带来了问题。
// main.c
void clean_buffers(void); // prototype
struct DEV_STATUS {
unsigned char ADDR;
unsigned char DEV_HAS_DATA;
unsigned char ETH_HAS_DATA;
unsigned char DATA[20];
};
struct DEV_STATUS g_cmdQueue[60] = {0};
void main(void) {
clean_buffers();
while (1) {
;// MCU tasks
}
}
void clean_buffers(void) {
unsigned char theCount = 0;
byte queIdx;
for (queIdx = 0; queIdx < 59; queIdx++) {
struct DEV_STATUS *p_struct;
unsigned char *p_data;
p_struct = &g_cmdQueue[queIdx];
p_data = &p_struct->DATA;
p_struct->ADDR = 0;
p_struct->DEV_HAS_DATA = 0;
p_struct->ETH_HAS_DATA = 0;
theCount = 0;
while(*(p_data+theCount) != 0) {
*(p_data+(theCount++)) = 0;
}
}
} // EOF main.c
我在以下行收到编译器错误“struct/union member expected” :
p_data = &p_struct->DATA;
例如,如果我要访问结构成员 DATA[3] 的特定值,我应该如何编写指针?我很困惑,我认为 p_data = &p_struct->DATA; 已定义,我应该能够通过使用 *(pdata+3) 来获得它,但我想我错过了一些东西。