我想知道为什么我会得到这个,
错误:
error: dereferencing pointer to incomplete type
strncpy(variables->part1[i], environ[i], placement);
主要代码:
struct vars {
char **part1;
char **part2;
} ;
static struct vars *variables;
exportenviron(&variables);
函数代码:
void exportenviron(struct vars* variables)
{
int i;
char *pch;
int placement;
for(i=0; environ[i]; i++) {
pch = strchr(environ[i], '=');
placement = pch-environ[i]+1;
strncpy(variables->part1[i], environ[i], placement);
}
}
最佳答案
包含 exportenviron
的文件没有看到您的结构的实际定义:相反,它只知道 struct vars
存在,但不知道其中的内容。例如,也许您有一个头文件 vars.h
包含在 .c 文件中,其中包含 exportenviron
,而 vars.h
仅包含结构变量;
关于c - 在 C 中取消引用指向不完整类型错误的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25902667/