奇怪的错误(取消引用指向不完整类型的指针)

void get_cwd(char* buf) { char *result; current->fs->pwd; result = get_dentry_path(current->fs->pwd); memcpy(buf, result, strlen(result)+1); kfree(result); } 

错误:取消引用指向不完整类型的指针

错误指向current-> fs-> pwd;

包括:

 #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  

如果我键入current-> fs; 在第5行gcc不会在这一行给出错误。 问题在于pwd字段。

这个问题有点陈旧,但我再次尝试在内核v2.6.33中实现getcwd遇到同样的问题。 由于这是搜索“取消引用指向不完整类型current-> fs的指针”时出现的最相关的结果,因此最好有解决方案以供将来参考。

解决方案是包含以下两个标头:

 #include  #include  

error: dereferencing pointer to incomplete type意味着您尝试访问不透明数据结构中的数据。 不透明的数据结构通常只是头文件(.h *)中的typedef ,在实现文件(.c *)中具有实际定义,并且只能由实现访问。 这用于隐藏实现细节,仅通过标头提供的接口API提供对元素的访问。

http://en.wikipedia.org/wiki/Opaque_pointer

http://lxr.linux.no/#linux+v2.6.33/include/linux/fs_struct.h#L11 – 这应该有用; current应该是struct task struct的指针,它应该包含一个指向struct fs_struct fs的指针,它应该包含struct path pwd 。 也许您需要包含fs_struct.h,以便可以看到struct fs_struct的内容。

好吧,错误信息和你的实验显然意味着current->fs是指向不完整类型的指针。 这里的所有都是它的。 为什么你认为它“奇怪”?