I keep running across little conventions like
__ in this case a naming convention used by kernel developers or is it a syntax specific reason for naming a macro this way?
There are many examples of this throughout the code.
For example some functions and variables begin with an
_ or even
Is there a specific reason for this?
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.
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?Answer1:
There are several cases:<ul><li>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.</li> <li>In internal code, the convention usually is that symbol
__somethingis workhorse for
somethingexcluding some management, often locking. That is a reason for things like
__d_lookup. Similar convention for system calls is that
sys_somethingis the system call entry point that handles context switch to and from kernel and calls
do_somethingto do the actual work.</li> <li>The
_tsuffix is standard library convention for typedefs. E.g.
foff_tand such. Kernel code follows this convention for it's internal types too.</li> </ul>