Preface: 3 Years of work, it is time to summarize the thought of the 3 years, to build their own knowledge system, the formation of programming ideas, the basis and application of knowledge between the channel need to get through, then start it.
"C and Pointers"
Chapter III 3.3 typedef
1. C language support typedef mechanism;
2. typedef is used to define new names for various data types;
3. typedef declaration types can reduce the risk of making the statement smelly and long;
4. Use typedef instead of # define to create a new type name because the latter does not handle the pointer type correctly.
Code Specification Summary:
In the process of working, the introduction of TCP/IP protocol stack, file system, often in the introduction of these external libraries and modules, will introduce a new data type definition, resulting in a project, sometimes there will be 5, 6 completely different naming methods of the basic data type, which is very undesirable, It brings a lot of inconvenience to code maintenance and development, so the following suggestions are made:
1. The introduction of the library or module, regardless of development or maintenance, maintain the original basic data type unchanged;
2. New development module, based on a unified and unique basic data type development;
3. Based on the development of external libraries and modules, use the same and unique basic data type development.
Usage Experience Summary:
In Linux storage management, there is the following code
typedef struct {unsigned long pte_low;} pte_t;
#define PTE_VAL (x) ((x). Pte_low)
The use of this, indeed very good, using the object-oriented programming approach, brings the following benefits:
1. What happens if the code uses the following implementation method?
#define unsigned long pte_t;
This can cause a problem
unsigned long new_pte;
pte_t new = New_pte; compiler does not error, this is the hidden danger
This article is from the "mountain Ask the Boy" blog, please be sure to keep this source http://linpeng.blog.51cto.com/9779987/1685081
3.3 typedef__ 3rd data "C and pointers"