什么是领导和Linux内核标识符尾随下划线的意思? [英] What is the meaning of leading and trailing underscores in Linux kernel identifiers?
问题描述
我把整个小约定运行像 __ __仁
。
I keep running across little conventions like __KERNEL__
.
是 __
在这种情况下所使用的内核开发人员或命名约定是它命名宏这样一个语法具体的原因?
Are the __
in this case a naming convention used by kernel developers or is it a syntax specific reason for naming a macro this way?
有整个code许多这样的例子。
There are many examples of this throughout the code.
例如某些函数和变量开始与 _
甚至 __
。
For example some functions and variables begin with an _
or even __
.
有没有具体的原因?
这似乎pretty广泛使用,我只是需要一些澄清,这些东西是否有语法的目的还是纯粹的命名约定。
It seems pretty widely used and I just need some clarification as to whether these things have a syntactical purpose or is it simply a naming convention.
此外,我看到很多的用户声明类型,比如将uid_t。同样我想这是一种命名约定,告诉读者,这是一个用户定义的类型?
Furthermore I see lots of user declared types such as uid_t. Again I assume this is a naming convention telling the reader that it is a user-defined type?
推荐答案
有几种情况:
- 在面向公众的标题,即任何在libc将接管和下把
在/ usr /在include / linux
,该标准规定了哪些符号应定义和任何其他具体到系统符号应下划线和大写字母或两个下划线开始。这是__ __仁尤其是的原因,因为它是在都在内核和libc和一些声明是不同的包括头使用。
- 在内部code,习惯通常是符号
__东西
是的东西
不包括一些管理的主力,常锁定。这是对于像__ d_lookup
的原因。系统调用类似的约定是sys_something
是处理上下文切换,并从内核调用系统调用入口点do_something
做实际工作。 - 的
_t
的后缀是typedef的标准库约定。例如。为size_t
,ptrdiff_t的
,foff_t
和这样的。内核code遵循了这一约定为它的内部类型了。
- In public facing headers, i.e. anything that libc will be taking over and putting under
/usr/include/linux
, the standards specify which symbols should be defined and any other symbols specific to the system shall start with underscore and capital letter or two underscores. That's the reason for__KERNEL__
in particular, because it is used in headers that are included both in kernel and in libc and some declarations are different. - In internal code, the convention usually is that symbol
__something
is workhorse forsomething
excluding some management, often locking. That is a reason for things like__d_lookup
. Similar convention for system calls is thatsys_something
is the system call entry point that handles context switch to and from kernel and callsdo_something
to do the actual work. - The
_t
suffix is standard library convention for typedefs. E.g.size_t
,ptrdiff_t
,foff_t
and such. Kernel code follows this convention for it's internal types too.
这篇关于什么是领导和Linux内核标识符尾随下划线的意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!