Shu*_*yon 3 c struct pointers header dereference
大家好!
我在尝试测试游戏Clever Frog的代码时遇到以下错误: 错误:取消引用指向不完整类型的指针
'完整代码'位于pastebin.com - 此处(不会过期).但我认为,通过下面的解释,任何人都可以理解.注意:我还没有实现将擦除分配的内存和其他东西的功能.
我在1.c文件中定义了一个结构:
#include "1.h"
...
struct test {
int a;
};
...
Run Code Online (Sandbox Code Playgroud)
我有一个1.h wicth有typedef使用它:
...
typedef struct test testT;
...
Run Code Online (Sandbox Code Playgroud)
然后我有一个函数,其中有一个参数取决于testT,它在2.c:
...
void funcTest(testT **t, int *size, ..){
/* another function that creates mem.space/alocate memory based enter code here`on the need of size above */
createMem(t,*size); /* void createMem(testT **t, int size); */
t[0]->a = 0; /*ERROR HERE*/
/* ... more code ... */
}
...
Run Code Online (Sandbox Code Playgroud)
2.h文件是这样的:
...
void funcTest(testT **t, int *size, ..);
...
Run Code Online (Sandbox Code Playgroud)
我将在主程序中以下面的方式传递testT*var:
...
testT *varTest; int size;
funcTest(&varTest, &size);
...
Run Code Online (Sandbox Code Playgroud)
奇怪的是,我在1.h文件中使用struct test时编译代码(从1.c中删除struct test - 这是错误的).但是,当运行编译的程序时,错误发生的确切位置是t [0] - > a的位置.
我已经尝试了"一切"但没有任何效果:(我相信这是非常愚蠢的事情,所以如果有人知道的话,请告诉我:D谢谢!
当您尝试访问结构的a成员时,t[0]编译器需要知道此结构的外观(例如,查看其中是否还有任何a成员).由于您没有将struct test类型定义放在编译器在编译时可以看到的任何位置,因此2.c会出现错误.编译器不知道struct test包含什么.
如果你输入struct testin 的定义1.h,编译器会看到该类型的样子,并且可以使用struct成员.
只需将完整的类型定义放入其中1.h,即它应该是的位置.
| 归档时间: |
|
| 查看次数: |
35331 次 |
| 最近记录: |