Why are these function names in parenthesis?

773 Views Asked by At

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

There are 3 best solutions below

0
On

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.

7
On

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.

0
On

These are function pointers and not the function names. So they can point to any function of same type and properties.