C 内核模块中的静态函数原型
我正在阅读《LKM开发手册》,遇到以下例子: 我感到困惑的是,有人建议将C 内核模块中的静态函数原型,c,linux,linux-kernel,kernel-module,C,Linux,Linux Kernel,Kernel Module,我正在阅读《LKM开发手册》,遇到以下例子: 我感到困惑的是,有人建议将静态非-内联声明放在头文件中。原因是什么 如果我们不应该在除驾驶室以外的任何地方使用这些与驾驶员相关的功能 struct file_operations fops = { .open = device_open, .release = device_release, .read = device_read, .write = device_write }; static int init_m
静态非-内联声明放在头文件中。原因是什么
如果我们不应该在除驾驶室以外的任何地方使用这些与驾驶员相关的功能
struct file_operations fops = {
.open = device_open,
.release = device_release,
.read = device_read,
.write = device_write
};
static int init_module(void){
int register_result = register_chrdev(&fops);
//...
}
在模块初始化期间,我们可以简单地将它们的静态定义放在这里,从而避免原型声明。否则,它们应该(应该?)用外部链接声明。绝对不需要将静态
非内联
声明放在单独的头文件中
如果驱动程序非常复杂,device.*
方法的定义可以安排到不同的源文件中(并且file\u操作的定义也可以安排到自己的源文件中),但是在这种情况下,应该删除static
说明符。它们被声明为static,以避免污染内核名称空间。
struct file_operations fops = {
.open = device_open,
.release = device_release,
.read = device_read,
.write = device_write
};
static int init_module(void){
int register_result = register_chrdev(&fops);
//...
}