Questions raised
Please analyze This declaration: void (*signal (int sig, Void (*handler) (int))) (int);
Solution Process
Before analysing the above example, we need to understand the C language declaration priority, "C expert Programming" P64 the original text as follows:
Rule a stipulates that the declaration should be interpreted according to priority (a nonsense). Rule C Please refer to my previous note: http://www.cnblogs.com/deyuanqin/p/5705967.html. The specific practice process of rule B is as follows:
For the purposes of this, we use the above rules to analyze the complex declaration of Void (*signal (int sig, Void (*handler) (int) )) (int). From easy to difficult order:
1. void (*handler) (int):
① Handler to the right of the parentheses, so handler is not an array or function. Then look at the left side, which is * (asterisk), so handler is a pointer to * * * * .
② (*handler) (int). The right side of (*handler) is a parenthesis, so (*handler) (int) is a function that returns * * * * * . In conjunction with the previous analysis, handler is a pointer to a function that returns a * * * *.
③ (*handler) (int) has no symbol on the right and void on the left. In summary, handler is a pointer to a function that returns a void value .
2. void (*signal (int sig, Void (*handler) (int))) (int):
void (*handler) (int) has been parsed in the above steps, and we can use statement typedef void (*handler) (int) to simplify it (declaring handler as a new type, This type is a pointer to a function that returns a void value. For a further analysis of the typedef's knowledge, void (*signal (int sig, void (*handler))) (int) is reduced to void (*signal (int sig, handle h)) (int). Below we analyze void (*signal (int sig, handle h)) (int):
① Signal to the right of the parentheses, so signal () is a function that returns * * * * .
The left side of ② signal () is *, so signal () is a function that returns pointers to * * * * * .
The right side of the ③ (*signal (int sig, handle h)) is a parenthesis, so (*signal (int sig, handle h)) (int) is a function that returns * * * * * . In summary, signal is a function that returns a pointer to the return function .
④ (*signal (int sig, handle h)) is void on the right. Thus, signal (this identifier) is a function that returns a pointer to a function that returns a void value .
The above analysis process may have some errors, please crossing more advice.
Resources
1. "C Expert Programming" P65 Figure 3-1
2. Blog http://blog.csdn.net/jiuyueguang/article/details/9350903
C Language Complex declaration-void (*signal (int sig, Void (*handler) (int))) (int);