nebakke@ndsuvax.UUCP (Jeff Bakke) (10/13/89)
I have recently been working with function pointers and I have a problem
that I need help with.
say I have a function pointer defined:
void (*border_proc)();
Ok, now I want a function to be called as
Assign_border(myfunction);
Where myfunction is a function name.
Now the assign_border function
is declared as
void Assign_border(void (*user_border)()){
border_proc = user_border;
}
Now, to me, this seems alright, but to the Turbo c 2.0 compiler, it
says that a Storage class is required. Now, I've tried other variations
of the argument declaration but nothing I do works. Someone out there
must know the correct way to do this, if you do, I'd appreciate your
help.
Thanks.
Jeff bakke
nebakke@plains.NoDak.edu
nu113738@ndsuvm1.bitnet
kremer@cs.odu.edu (Lloyd Kremer) (10/13/89)
In article <3005@ndsuvax.UUCP> nebakke@ndsuvax.UUCP (Jeff Bakke) writes: >say I have a function pointer defined: >void (*border_proc)(); >Ok, now I want a function to be called as >Assign_border(myfunction); >Where myfunction is a function name. >Now the assign_border function >is declared as >void Assign_border(void (*user_border)()){ > > border_proc = user_border; >} > >Now, to me, this seems alright, but to the Turbo c 2.0 compiler, it >says that a Storage class is required. The code seems basically all right. Maybe the Assign_border function doesn't know what border_proc is. This could be the case if border_proc's definition were in another file or occurred before the Assign_border function. Try extern void (*border_proc)(); /* extern could be the missing storage class */ border_proc = user_border; as the contents of Assign_border(). -- Lloyd Kremer ...!uunet!xanth!kremer Have terminal...will hack!
cpcahil@virtech.UUCP (Conor P. Cahill) (10/14/89)
In article <3005@ndsuvax.UUCP>, nebakke@ndsuvax.UUCP (Jeff Bakke) writes: > Now, to me, this seems alright, but to the Turbo c 2.0 compiler, it > says that a Storage class is required. Assuming that the code you compiled looked as follows: void (*border_proc)(); void Assign_border(void (*user_border)()){ border_proc = user_border; } You should have had no problems with a compiler that correctly handles the new ANSI formal parameter declarations. pcc on 386/ix doesn't handle it, but the fix was simple: void Assign_border(user_border) void (*user_border)(); { border_proc = user_border; } gcc correctly handles either case. -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+