Linux kernel interface specific type

Some kernel data types commonly used have their own typedef statements, thus preventing any portability issues. For example, a process identifier (pid) often pid_t instead of int. Pid_t blocked using actual data on any type of different. we use the interface-specific expression refers to a type, a library of defined, so as to provide an interface to a particular data structure.

 

Note that, in the near future, has been relatively little new interface defined a specific type using typedef statements have been many kernel developers do not like, they'd rather see real code type information directly, not hidden behind a user-defined type. many older specific types of interfaces kept in the kernel, however, and they are not going away anytime soon.

 

Even when not define a specific type of interface, in a manner and other parts of the kernel consistent with the correct data type has been important. A tick count, e.g., it has been unsigned long, independent of its actual size, so unsigned long type should always be used when using a jiffy. in this section we focus on the _t types.

 

Many _t types are defined in <linux / types.h>, a listed but is rarely useful when you need a specific type, you'll find it in the function prototype you need to call in, or use your data in structure.

 

Whenever you need to use this drive "Custom" type of function and you do not follow convention, the compiler issues a warning; if you use the -Wall compiler flag and carefully remove all the warnings, you can have confidence that your code is portable.

 

The main problem _t data items is when you need to print them, often not easy to choose the right printk or printf format, warning you that appears on a system will reappear in another. For example, how do you print a size_t, it on some platforms are unsigned long while in some other top is unsigned int?

 

Whenever you need to print a specific data interfaces, the best way is to convert its maximum possible value type (often long or unsigned long) and then print it. This adjustment is not produced by a corresponding format errors or warnings because the format match type, and you will not lose data bits because this extension or conversion is a no-op or data items to a larger data type.

 

In fact, we're talking about items not often you want to print, so this problem only applies to debugging information. Often, the code only needs to store and compare specific types of interfaces, plus they are passed as arguments to library or kernel functions .

 

Although _t types are the right solution in most cases, and sometimes not access the correct type. This occurs when some have not been cleaned up old interface.

 

 

 

We found a ambiguities in the kernel header file is used in the data type I / O function, which is loosely defined

 Loose type mainly because of historical reasons, but it may have in there at the time of writing code issues such as the exchange to function as outb parameters may be in trouble; if there is a port_t type, the compiler will find this type.

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11146085.html