C Language Complex declaration-void (*signal (int sig, Void (*handler) (int))) (int);

Source: Internet
Author: User

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.