gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 00:19:45 25 4
gpt4 key购买 nike

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 <asm/stat.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/dirent.h>
#include <linux/sched.h>
#include <asm/uaccess.h>
#include <asm/current.h>
#include <linux/path.h>

如果我输入 current->fs;在第 5 行,gcc 不要在此行给出错误。问题出在 pwd 字段上。

最佳答案

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

解决方案是包含这两个 header :

#include <linux/sched.h>
#include <linux/fs_struct.h>

关于c - 奇怪的错误(取消引用指向不完整类型的指针),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2693393/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com