C/C ++ function pointer declaration and function pointer Declaration
I watched APUE the day before yesterday and saw that the signal statement was actually
Void (* signal (int, void (*) (int );
I can't see what it means. This function pointer can only be seen when the Tao is too light.
Void * (* func) (int, void (*) (int ));
In the book, we can see the pointer below typedef first.
Typedef void Signfunc (int );
Signfunc * signal (int, Sigfunc *);
This is indeed clear, but I don't know why it should be so analyzed, why it is not written
(Void (int) (* signal) (int, void (*) (int ));
This is not easy to understand, and then I compile it in gcc, it says
Error: expected identifier or '('before' void'
(Void (int) (* signal) (int, void (*) (int ));
I changed it and said:
Error: expected identifier or '('before' int'
Void (int) (* signal) (int x, void (* func) (int ))
Error: 'signal 'declared as function returning a function
Void (* signal) (int, void (*) (int );
Error: 'signal 'declared as function returning a function
Void (* signal) (int, void (*) (int );
It seems that it only recognizes this type. I really don't know what old beauty thinks, so hard to recognize it.
It seems that this rule can only be used:
If the returned function is not a function pointer, the function pointer can be defined as follows:
Return Value of test (* test) (type parameter of test );
If a function pointer is returned, we need to write it:
Return the return value of the function (* test (the parameter of test) (returns the type parameter of the function );
Then it can be combined into various horrible function declarations.
Void (* signal (int, void (*) (int ));
It is A function pointer A, which returns A function pointer B, which is A function that returns the Function C value. Remove the complex parameters first.
Void (* signal (int );
#include <stdio.h>void (*((*signal(int))(int)))(int);void (*fun(int))(int);void test(int);int main(int c, char ** v){signal(323);return 0;}void (*((*signal(int x))(int)))(int){printf("num:%d",x);return fun;}void (*fun(int y))(int){return test;}void test(int x){printf("fuck C function pointer!!!,%d",x);}
We can continue
Is A function pointer A, which returns A function pointer B, which is A function that returns A function C value needle, function C is a function that returns the function D pointer ......
Personal blog address: http://www.flakor.cn
How does C declare a function that returns a function pointer?
Typedef int (* AA )();
AA function ();
C language question: how to declare a pointer to any type of function?
It doesn't matter what pointer is defined, and it can be forced conversion.
The key is that the parameters of the passed function should not be arbitrary.