[comp.graphics] Function pointer help

nebakke@ndsuvax.UUCP (Jeff Bakke) (10/13/89)

I have been working with function pointers in a program of mine and
have run into a stumper.  Maybe I'm just not reading the manuals
correctly but what syntax do I use for the following setup:

/* declaration */
void (*border)();     /* a function pointer to a window border function */

...

void set_user_border(void *user_border){

  border = user_border;
}

Now the problem occurs when I compile in that it returns an error
(turbo c 2.0 by the way) stating that I need a storage type or something
like that.

What I'm trying to do, is set border to point to a user defined border
function that is created outside of the library.  The user would call the
function as:
set_user_border(myfunction);
And then supposedly  border would then point to myfunction.  Somehow I
get the feeling that I'm setting up the parameter wrong but I don't know
what the correct declaration is.
I've tried (void (*user_border)()) but that still crashes.  

Could someone point me in the right direction.

Thanks for the help.


Jeff bakke
nebakke@plains.nodak.edu
nu113738@ndsuvm1.bitnet

hammondp@ingr.com (Paul Hammond) (10/17/89)

in article <3003@ndsuvax.UUCP>, nebakke@ndsuvax.UUCP (Jeff Bakke) says:
> Posted: Fri Oct 13 00:02:03 1989
> 
> I have been working with function pointers in a program of mine and
> have run into a stumper.  Maybe I'm just not reading the manuals
> correctly but what syntax do I use for the following setup:
> 
> /* declaration */
> void (*border)();     /* a function pointer to a window border function */
> 
> ...
> 
> void set_user_border(void *user_border){
> 
>   border = user_border;
> }
> 
> Now the problem occurs when I compile in that it returns an error
> (turbo c 2.0 by the way) stating that I need a storage type or something
> like that.

[ stuff deleted ]

> I've tried (void (*user_border)()) but that still crashes.  

The second form :

  void set_user_border (void (*user_border)()) 
   {
    ...
   }

should work.  Perhaps there is some complicating factor.  Look for all
the usual problems (missing semicolon, unmatched braces, comment delimiters
etc.).  Try it all by itself - without other code and declarations.
This works with a Green Hills compiler on an Intergraph workstation.
I've got TC2 at home but haven't tried this there.


						Paul L. Hammond
						ingr!b17b!ocelot!paul