[英]C error : assignment to expression with array type
I have developed a C code for my module but when I try to compile it, an error occurs.我为我的模块开发了 C 代码,但是当我尝试编译它时,出现错误。
This is the part of program where the error exist:这是存在错误的程序部分:
ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {
struct file *f = pfile->private_data;
enum { MAX_BUF_SIZE = 4096 };
size_t buf_size = 0;
char *buf = NULL;
ssize_t total = 0;
ssize_t rc = 0;
struct input_event ev[buf_size];
int yalv;
/* Allocate temporary buffer. */
if (length) {
buf_size = min_t(size_t, MAX_BUF_SIZE, length);
ev = kmalloc(buf_size, GFP_KERNEL);
if (ev == NULL) {
return -ENOMEM;
}
}
And this is the error:这是错误:
exer_simple_char_drv.c:77:12: error: assignment to expression with array type
ev = kmalloc(buf_size, GFP_KERNEL);
^
I don't know how to solve this.我不知道如何解决这个问题。 Could anyone help me out please.
谁能帮帮我。 Thanks
谢谢
If you want to allocate memory for ev
dynamically, as in:如果要为
ev
动态分配memory,如:
ev = kmalloc(buf_size, GFP_KERNEL);
then you want ev
to be a pointer, not an array with automatic storage duration:那么你希望
ev
是一个指针,而不是一个具有自动存储持续时间的数组:
struct input_event *ev;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.