Tom*_*eck 1 c arrays struct global-variables
只是想知道,您如何使用结构的全局数组?
例如:
int y = 0;
object objectArray [100];
typedef struct object{
time_t objectTime;
int objectNumber;
} object;
int main(void)
{
while(1)
{
time_t time_now;
time_now = time(NULL);
object x = {time_now, objectNo}
objectArray[y] = x;
y++;
}
}
Run Code Online (Sandbox Code Playgroud)
这总是会引发“错误:数组类型具有不完整的元素类型”,有人可以告诉我问题和适当的解决方案吗?谢谢
将结构体的定义移至数组声明之前:
typedef struct object{
time_t objectTime;
int objectNumber;
} object;
object objectArray [100];
Run Code Online (Sandbox Code Playgroud)
您收到该错误是因为编译器不知道object它何时到达数组声明的大小。