[Cs3] CS III Parameter passing with function pointers
Mikhail Nesterenko
mikhail at cs.kent.edu
Wed Feb 27 10:43:53 EST 2019
> I'm e-mailing you to figure out whether or not we can pass parameters when
> using auto to declare a function pointer, since you can normally use:
> int (*fp)(arguments) = myFunc;
When a function pointer is declared, a signature of the function that
the pointer may point two is specified. For example
int (*fp)(int, string);
Specifies that fp may point to functions that return int and take two
parameters: integer and a string, both by value.
Like any pointer, a function pointer may be assigned a value: the
address of a function. A function name is a constant function
pointer. So the assignment may happen like this:
fp = myfunc;
It may happen at declaration:
int (*fp)(int, string) = myfunc;
The signature of myfunc should be the same as fp.
After fp points to a function it may be invoked as a regular
function. For example:
int i;
i = fp(55, "hello");
Thanks,
--
Mikhail
More information about the cs3
mailing list