void error(int i); void (*p)(int); p=&error; (*p)(1);
To begin with, I will try to read the second line, that is, p is a pointer to a function that returns values of type void. Why I read this and in particular the "void type" because I used the technique from here . But what are the rules for all this?
I roughly understand it as:
- the implementation of the function (just for example, and the announcement was also there, but it did not write here);
- already read it above, I will add only that the grouping brackets are necessary in order that there was a pointer to a function, and not the name of the function and its returning type
void*. It is strange that after reading a single book on C ++, I did not meet there mention of the main type and derivative, and for this reason I was surprised by this record, what can we say about such
int (*(*foo)())();, it would be generally a dark forest, if not for that technique.
- Here the pointer "p" is assigned an address, but what is the address for the function prototype?
- The pointer is dereferenced and the function name
errorsimply substituted in its place and
(error)(1)obtained? That is, it is possible to wrap any function with grouping brackets and this does not change the essence.
Such a record is needed only because it is required by pointers, that is, so that the pointer has the same type as the specified object?