函数声明不是C中的原型

Thi*_*ruG 7 c compiler-errors linux-kernel

我正在学习为初学者编写Linux内核模块.我要做的是使用DFS算法将每个任务及其子进程写入内核日志.但是当我使用编译代码时Makefile,它显示上面的错误:

function declaration isn’t a prototype [-Werror=strict-prototypes]
struct task_struct *current;
Run Code Online (Sandbox Code Playgroud)

task_struct在函数DFS中指出了关键字.这是我的代码:

# include <linux/init.h>
# include <linux/kernel.h>
# include <linux/module.h>
# include <linux/sched.h>
# include <linux/list.h>

void DFS (struct task_struct *task)
{
    struct task_struct *current;
    struct list_head *list;

    list_for_each (list, &task->children)
    {
        current = list_entry(list, struct task_struct, sibling);
        printk(KERN_INFO "%d\t%d\t%s \n", (int)current->state, current->pid, current->comm);

        if (current != NULL)
        {
            DFS(current);
        }
    }
}

int DFS_init(void)
{
    printk(KERN_INFO "Loading the Second Module...\n");

    printk(KERN_INFO "State\tPID\tName\n");

    DFS(&init_task);   

    return 0;
}

void DFS_exit(void)
{
    printk(KERN_INFO "Removing the Second Module...\n");
}
Run Code Online (Sandbox Code Playgroud)

谁知道如何解决这个问题?

Thi*_*ruG 5

内核具有一个称为的宏current,该宏指向当前正在执行进程的用户。正如这本书所述,

当前指针是指当前正在执行的用户进程。在执行系统调用(例如打开或读取)的过程中,当前进程是调用该调用的进程。

换句话说,如@GilHamilton评价所提到的,current#defineD相对于功能get_current()的籽粒。

因此,将其current用作变量名将产生编译时错误!