Although #define语句看起来象typedef, there are actually differences in nature. For #define来说, the source code is only treated for string substitution prior to compilation, and for typedef It establishes a new data type alias. This shows that pch1 is defined as a pointer variable, but does not implement the programmer's intention, but instead defines PCH2 as a char variable.
In pointer functions, there is a class of functions that also return pointers, but this pointer is not a basic type, such as int, char, but rather a pointer to a function. For beginners, do not write such a function declaration, is to see this writing is also confused. For example , the following statement:
int (*ff (int)) (int *, int);
We use the method described above to analyze theFF first with the following "()" combination, namely:
Int (*(FF (int)))) (int *, int); enclose the FF (int) in parentheses.
It also means thatFF is a function.
Then, in conjunction with the previous "*", it is stated that the return value of the FF function is a pointer. Then it is combined with the following "()", which means that the pointer is pointing to a function.
This kind of writing is really very difficult to understand, so that some beginners have misunderstood, think that people can not understand the code to show their level of high. In fact, in contrast, the ability to write easy-to-understand code is a measure of whether a programmer is good or not. In general, using the TypeDef keyword makes the declaration easier to understand. In the front we have seen:
Int (*PF) (int *, int);
In other words,pf is a function pointer " variable ". When a typedef declaration is used, the pf becomes a function pointer " type ", i.e.:
typedef int (*PF) (int *, int);
This defines the type of the return value. Then, use PF as the return value to declare the function :
PF ff (int);
C-language typedef