Mail Archives: djgpp/1999/02/28/18:10:40
> <------------------------ wrote:
>
> Hi,
>
> I'm in the process of writing a (very primitive) scrolling shoot-em-up
> like space invaders,
> and in designing the core of the sprite moving program, I have chosen
> to have every object
> call it's update function each frame. All the objects share a common
> data type, so I wanted
> to use function pointers. The problem is, I've never uesd them before.
> Just wanted to know
> how to prototype them (if any changes are needed) and how to specify
> them in my object_t
> structure. I'd also appreciate any help in how I'm supposed to assign
> functions to the pointers,
> and how to call those functions.
Please don't post in HTML.
A function pointer is declared basically like this:
int (*this_is_a_function_pointer)(int, int);
which makes `this_is_a_function_pointer' a pointer to a function taking
two `int' arguments and returning `int'. Assuming you have a function
like:
int foo(int, int);
you can then do
this_is_a_function_pointer = foo;
or
this_is_a_function_pointer = &foo;
In the case of functions, you can use the `&' operator or not; whichever
you feel is clearer.
There is a program on Simtelnet called `cdecl' that can help with
complicated declarations.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -