Overview
In many cases, especially when reading other people's written code, the ability to understand the C language statement becomes very important, and the C language itself concise also makes the C language statement is often very confusing, so here I use a content to focus on this issue.
Issues: Declarations and functions
A program is stored in a section of memory starting at 0, and if we want to call this program, how do I do it?
Answer
The answer is (* (void (*) ()) 0) (). It looks really big, that's good, let's be hard to understand, from two different ways to analyze the problem in detail.
Answer analysis: From the end of the head
First, the most basic function declaration: void function (paramlist);
The most basic function call: Functions (Paramlist);
Given that the function in the problem has no parameters, the function call can be simplified to functions ();
Secondly, according to the description of the problem, you can know that 0 is the entry address of this function, that is, 0 is a pointer to a function. function declarations using function pointers are: void (*pfunction) (), and the corresponding invocation form is: (*pfunction) (), the function call in the question can be written: (*0) ().
Third, as you know, a function pointer variable cannot be a constant, so 0 of the upper formula must be converted to a function pointer.
Let's take a look at a function that uses a function pointer: void (*pfunction) (), what is the prototype of the function pointer variable? The problem is simple: the Pfunction function pointer prototype is (void (*) ()), which is to remove the variable name, and for clarity, the whole plus () number.
So casting 0 to a return value of void with null arguments is the following: (Void (*) ()).
OK, combine 2 and 3), the results come out, that is: (* (Void (*) ()) 0) ().
Answer Analysis: Understand the answer from beginning to end
(Void (*) ()) is a function pointer prototype with a return value of void and an empty argument.
(Void (*) ()) 0, convert 0 to a function pointer with a return value of void, a null argument, and a pointer to an address of 0.
* (void (*) ()) 0, preceded by * means the name of a function whose return value is void
(* (Void (*) ()) 0) (), which of course is a function.
We can use the typedef to clearly declare the following:
typedef void (*pfun) ();
This function becomes (* (pfun) 0) ();