Linux kernel 4.9 programming



mknod /dev/chardev c 248 0

参数说明: c 为char device 字符设备的意思,248为主设备号,0为次设备号

error: function declaration isn’t a prototype

/usr/src/program/procfs1.c:31:6: error: function declaration isn’t a prototype [-Werror=strict-prototypes]
 void create_new_proc_entry(){


In C int foo() and int foo(void) are different functions. int foo() accepts an arbitrary number of arguments, while int foo(void) accepts 0 arguments. In C++ they mean the same thing. I suggest that you use void consistently when you mean no arguments.

If you have a variable a, extern int a; is a way to tell the compiler that a is a symbol that might be present in a different translation unit (C compiler speak for source file), don’t resolve it until link time. On the other hand, symbols which are function names are anyway resolved at link time. The meaning of a storage class specifier on a function (extern, static) only affects its visibility and extern is the default, so extern is actually unnecessary.

I suggest removing the extern, it is extraneous and is usually omitted.

.read 格式

/usr/src/program/procfs1.c:15:11: error: initialization from incompatible pointer type [-Werror=incompatible-pointer-types]
   .read = procfile_read,

格式定义为 :

read_proc(struct file *filp,
      char __user *buf,
      size_t count,
      loff_t *offp){