Quote:
Originally Posted by trist007
What does this do exacty?
Code:
int(*fp)(void) = (int(*)(void))buf
This declares a function pointer that takes a void argument and returns an int. However I don't understand what this assignment does exactly.
|
int(*)() is a type and
int(*fp)() is the way you use it.
Code:
typedef int(*f_pointer)();
f_pointer fp = (f_pointer) buf;
The assignment takes the address of the function so that
*fp is a reference (in C++, anyway) to the function, which can be evaluated with
().
Code:
int value = (*fp)(); //normal function-pointer evaluation
int(&fp2)() = *fp; //also allowed in C++
value = fp2();
Kevin Barry