This is example for using function pointer in C. (basically, C++ case can be easily inferred from C's one)
Syntax related with function pointer type is quite different from other normal(?) one.
So, here is summary.
* type definition
typedef void (*<type name>) (int, void*);
* variable definition
void* (*<var name>) (int, void*) = NULL;
=> define function pointer variable that's type is "void*(*)(int, void*)" and initialize it into 'NULL'.
* type casting.
fpointer1 = (void*(*)(int, void*)) fpointer2;
=> cast function pointer 'fpointer2' into "void(*)(int,void*)" type.
* function that returns function pointer - float(*)(float, float).
=> float (*get_ptr(char c))(float, float); <- parameter is "char c", return type is "float(*)(float, float)"
* function - returns function pointer - pointer variable .
=> void(*(*var_name)(char c)) (void*); <- return function pointer type is "void(*)(void*)", parameter is "char c" and variable name is 'var_name'
* declare function pointer variable whose return type is function pointer.
=> int(* (*get_func)(int))(int, int); <- parameter of function is "int" And it returns function pointer "int(*)(int,int)"
* typecasting to function pointer whose return type is function pointer.
=> int(*(*)(int))(int, int); <- pointed function's return type is "int(*)(int,int)".
* array of function pointer.
=> static int(*array_name[])(float) = { ... }; <- "int(*)(float)" typed function pointer array.
* pointer of function pointer
=> void*(**<var name>)(int, void*); <- <var name> is pointer of function pointer. it's type is "void*(**)(int, void*)"
'Language > C&C++' 카테고리의 다른 글
[Linux][C/C++] Understanding Signals – User Signal Handler (0) | 2010.10.29 |
---|---|
[C/C++] type of hard-coded-string. (0) | 2010.09.16 |
[C/C++] Memory(Heap) alloc/free interface for the library. (0) | 2010.04.20 |
[C/C++] Mimicking Signal and Slot (0) | 2010.04.08 |
[C/C++] Intereseting compile error of Passing function pointer as an argument of template class member... (0) | 2009.09.28 |