在Linux设备驱动程序的静态功能? [英] Static functions in Linux device driver?

查看:106
本文介绍了在Linux设备驱动程序的静态功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有为什么在linux code设备驱动程序的大多数函数定义被定义为静态的理由吗?是否有一个原因?

Is there a reason why most function definition in device driver in linux code is defined as static? Is there a reason for this?

有人告诉我,这是范围界定和prevent污染名字空间,任何人都可以详细解释一下为什么静态清晰度是在这种情况下使用?

I was told this is for scoping and to prevent namespace pollution, could anyone explain it in detail why static definition is used in this context?

推荐答案

函数声明为static并不只在定义翻译单元外部可见(翻译单元基本上是一个.c文件)。如果函数不需要从文件以外调用,那么就应使静态以便不污染全局命名空间。这使得属于同一不太可能发生名称之间的冲突。导出的符号通常用中标识某种子系统吊牌,这进一步降低范围冲突。

Functions declared static are not visible outside the translation unit they are defined in (a translation unit is basically a .c file). If a function does not need to be called from outside the file, then it should be made static so as to not pollute the global namespace. This makes conflicts between names that are the same are less likely to happen. Exported symbols are usually indentified with some sort of subsystem tag, which further reduces scope for conflict.

通常,指针这些功能最终在结构,所以它们实际上是从它们被定义在文件以外调用,但不通过它们的功能名称

Often, pointers to these functions end up in structs, so they are actually called from outside the file they are defined in, but not by their function name.

这篇关于在Linux设备驱动程序的静态功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆