问题
I've been meaning to ask this question for a while now. What's going on with these functions? Why are the names in parenthesis?
void (*think)(gentity_t *self);
void (*reached)(gentity_t *self); // movers call this when hitting endpoint
void (*blocked)(gentity_t *self, gentity_t *other);
void (*touch)(gentity_t *self, gentity_t *other, trace_t *trace);
回答1:
In your examples, the parenthesis in function name means that variable of pointing the function address. If you don't use the parenthesis
void * think(gentity_t *self);// equal (void *) think(gentity_t *self);
It means the definition of a function with name:think, return: void *, parameter: gentity_t *self; These are the variable of the pointing the functions.
回答2:
These declarations are function pointers, which point to a function and can be changed at any time.
I suggest you do some research on function pointers in C because they are very useful.
If you know C++'s std::function
then these are effectively the old C version of them.
回答3:
These are function pointers and not the function names. So they can point to any function of same type and properties.
来源:https://stackoverflow.com/questions/45746922/why-are-these-function-names-in-parenthesis