Because of the awkward syntax, when you work with function pointers in C
or C++, you use a typedef. Here is a typedef for a pointer to a function
returning 'int' and taking a single 'int' argument:
typedef int (*funcPtr)(int);
int
foo(int x)
{
return (x * 2);
}
funcPtr myFuncPtr = &foo;
Actually I don't think the '&' is really required:
funcPtr myFuncPtr = foo;
Then call the function via the pointer:
myFuncPtr(1);
I hope this helps.
-Adam
On Sat, 29 Jul 2000, Andreas Schiffler wrote:
> Hi,
>
> I can't seem to figure out this simple C coding problem.
>
> I'd like to implement a callback function in C through by setting a
> pointer at runtime from an external program.
>
> A pointer is defined in a library as part of a structure. If the pointer
> is NULL nothing should happen. If the pointer is set by the external
> program that uses the library, the corresponding function that was
> defined _externally_ should be called.
>
> Can't figure out the syntax ... any ideas?
>
> Ciao
> Andreas
>
> --
> | Andreas Schiffler aschiffler@home.com |
> | Senior Systems Engineer - Deskplayer Inc., Buffalo |
> | 4707 Eastwood Cres., Niagara Falls, Ont L2E 1B4, Canada |
> | +1-905-371-3652 (private) - +1-905-371-8834 (work/fax) |
>
>
>
-- Saskatoon Linux Group Mailing List. -- To unsubscribe, send mail to 'linux-request@slg.org' with 'unsubscribe' in the body.Received on Sun Aug 6 19:09:57 2000
This archive was generated by hypermail 2.1.8 : Sun Jan 09 2005 - 13:54:00 CST