当我尝试为名为“struct car”的结构创建变量“c”时出现“错误:‘c’的存储大小未知”
代码如下:
teste.h
#ifndef TESTE_H_INCLUDED
#define TESTE_H_INCLUDED
typedef struct car Car;
#endif // TESTE_H_INCLUDED
teste.c
#include <stdio.h>
#include <stdlib.h>
#include "teste.h"
struct car{
char name[20];
char model[20];
};
main.c
#include <stdio.h>
#include <stdlib.h>
#include "teste.h"
int main()
{
Car c;
return 0;
}
我不明白为什么会出现此错误...我敢打赌这是愚蠢的...有人可以帮助我吗?
最佳答案
头文件中的 Car 结构只是一个前向声明,当它被包含在 main.c 中时,它只知道前向声明但不知道它是如何定义的(或者在这种情况下,它的大小是多少)结构是)。在头文件中定义结构。
struct car {
char name[20];
char model[20];
};
关于c - 错误 : storage size of 'c' isn't known,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29550877/