Is this a pointer to a common function
No, if I'm not mistaken, in C there is no such thing as a "universal function pointer".
and is it dangerous?
Yes it is. This evil.
There are a few things you need to know. Firstly, if you are not using a POSIX compliant system,
void(*test)() = (void*)add;
wrong. void * is a type of pointer to an object , and as such, it is incompatible with function pointers. (At least not in standard C - as I mentioned, POSIX requires it to be compatible with function pointers.)
Secondly, void (*fp)() and void (*fp)(void) different. The first declaration allows fp to accept any number of parameters of any type, and the number of arguments and their types will be displayed when the compiler sees the first function call (pointer).
Another important aspect is that function pointers are guaranteed to be converted into each other (AFAIK is manifested in them, having the same presentation and alignment requirements). This means that any function pointer can be assigned (address) to any function (after the appropriate cast), if you do not call the function using a pointer to an incompatible type. A behavior is correctly defined if and only if you call the pointer back to the original type before calling it.
So, if you need a βgenericβ function pointer, you can just write something like
typedef void (*fn_ptr)(void);
and then you can assign a function to any pointer to an object of type fn_ptr . You should pay attention to this, again, converting to the desired type when calling the function, as in:
int add(int a, int b); fn_ptr fp = (fn_ptr)add; // legal fp(); // WRONG! int x = ((int (*)(int, int))fp)(1, 2); // good