以下代码在不同文件中使用为啥出现语法错误 void checkAndUpdate(Openmv_InitTypeDef *myStruct); typedef struct Openmv { uint16_t Color_Num; uint16_t Shape_Num; uint16_t Openmv_X; uint16_t Openmv_Y; uint16_t Openmv_W; uint16_t Openmv_H; uint16_t flag; }Openmv_InitTypeDef; void checkAndUpdate(Openmv_InitTypeDef *myStruct) { static uint16_t prevData1, prevData2, prevData3, prevData4, prevData5, prevData6; if (myStruct->Color_Num != prevData1 || myStruct->Shape_Num != prevData2 || myStruct->Openmv_X != prevData3 || myStruct->Openmv_Y != prevData4 || myStruct->Openmv_W != prevData5 || myStruct->Openmv_H != prevData6) { myStruct->flag++; OpenmvArray[myStruct->flag] = *myStruct; // 保存之前的数据到结构体数组中 prevData1 = myStruct->Color_Num; prevData2 = myStruct->Shape_Num; prevData3 = myStruct->Openmv_X; prevData4 = myStruct->Openmv_Y; prevData5 = myStruct->Openmv_W; prevData6 = myStruct->Openmv_H; } }
时间: 2024-03-02 22:52:33 浏览: 76
这段代码出现语法错误是因为在使用它的文件中没有包含定义 Openmv_InitTypeDef 结构体类型的头文件。需要在使用它的文件中添加以下代码:
```c
#include "header_file.h" // 替换为实际的头文件名
// 或者直接在文件中定义结构体类型 Openmv_InitTypeDef
typedef struct {
uint16_t Color_Num;
uint16_t Shape_Num;
uint16_t Openmv_X;
uint16_t Openmv_Y;
uint16_t Openmv_W;
uint16_t Openmv_H;
uint16_t flag;
} Openmv_InitTypeDef;
// 然后再使用 checkAndUpdate 函数
void checkAndUpdate(Openmv_InitTypeDef *myStruct) {
static uint16_t prevData1, prevData2, prevData3, prevData4, prevData5, prevData6;
if (myStruct->Color_Num != prevData1 || myStruct->Shape_Num != prevData2 || myStruct->Openmv_X != prevData3 || myStruct->Openmv_Y != prevData4 || myStruct->Openmv_W != prevData5 || myStruct->Openmv_H != prevData6) {
myStruct->flag++;
OpenmvArray[myStruct->flag] = *myStruct; // 保存之前的数据到结构体数组中
prevData1 = myStruct->Color_Num;
prevData2 = myStruct->Shape_Num;
prevData3 = myStruct->Openmv_X;
prevData4 = myStruct->Openmv_Y;
prevData5 = myStruct->Openmv_W;
prevData6 = myStruct->Openmv_H;
}
}
```
其中,header_file.h 是定义 Openmv_InitTypeDef 结构体类型的头文件的文件名,需要替换成实际的头文件名。
阅读全文