gpt4 book ai didi

c - Linux驱动编写,file_operations incompatible pointer type错误

转载 作者:太空宇宙 更新时间:2023-11-04 03:11:04 29 4
gpt4 key购买 nike

我正在编写一个简单的 linux 驱动程序,它可以接受通过 CLI 传输的消息,但我收到了一个不兼容的指针类型错误。

我的读取函数和 file_operations 结构:

ssize_t driver_read(struct file *filep, char *buffer, ssize_t len, loff_t *offset) {
printk(KERN_INFO "Write: %s\n", message);
return 0;
}

struct file_operations fops = {
write: driver_write,
read: driver_read
};

当我尝试编译代码时出现以下错误:

error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
read: driver_read

根据这里的另一篇文章,读取函数的返回类型应该是 ssize_t,我有,但我仍然收到此错误。

最佳答案

尝试将原型(prototype)的参数更改为:

ssize_t len

为此:

size_t len

Source

关于c - Linux驱动编写,file_operations incompatible pointer type错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56312867/

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