【发布时间】:2011-07-13 15:04:23
【问题描述】:
大家好!
我在尝试测试 Clever Frog 游戏的代码时遇到以下错误: 错误:取消引用指向不完整类型的指针
“完整代码”位于 pastebin.com - here(不会过期)。但是我认为通过下面的解释,任何人都可以理解。注意:我还没有实现擦除分配的内存和其他东西的功能。
我在 1.c 文件中定义了一个结构:
#include "1.h"
...
struct test {
int a;
};
...
我有一个 1.h wicth 有 typedef 使用它:
...
typedef struct test testT;
...
然后我有一个函数,其中有一个取决于 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 ... */
}
...
2.h文件是这样的:
...
void funcTest(testT **t, int *size, ..);
...
我将在主程序中按以下方式传递 testT *var:
...
testT *varTest; int size;
funcTest(&varTest, &size);
...
奇怪的是,当我在 1.h 文件中使用 struct test 时,代码会编译(从 1.c 中删除 struct test - 这是错误的)。但是,在运行编译好的程序时,错误发生的地方正是t[0]->a的地方。
我已经尝试了“一切”但没有任何效果:(我相信这是非常愚蠢的事情,所以如果有人知道一些事情,请告诉我:D 谢谢!
【问题讨论】:
-
EDIT “奇怪的是,当我在 1.h 文件中使用 struct test 时,代码会编译(从 1.c 中删除 struct test - 这是错误的)。但是,运行编译后的程序时,出错的地方就是t[0]->a的地方。"错误是“分段错误”。
标签: c pointers header struct dereference