Passing functions in C
Brad Appleton
brad at SSD.CSD.HARRIS.COM
Tue Mar 13 03:13:32 AEST 1990
Sorry to post this folks!
I tried e-mail to both of her addresses but both bounced :-(
In article <1990Mar9.045151.9601 at ucselx.sdsu.edu> cynthia at ucselx.sdsu.edu (cynthia Anderson) writes:
>hello
>
>i would like to be able to write a procedure that takes as
>a parameter a procedure name and then using that name
>calls the procedure.
>
>ie runAProcedure(myProcedure)
> {
>
>
> myProcedure
>
>
>}
>
>Is this possible to do in C? Any help or advise is appreciated
>tho please e-mail responses so the net won't be cluttered.
>
>thanks,
>
>cynthia anderson
><cynthia at cod.nosc.mil.uucp>
>or
><cynthia at ucselx.sdsu.edu>
>
>Disclaimer: whenever it was and whenever it happened, i'm sure i
>wasn't there and it couldn't have been me.
NO! It is not possible to do in C! (Im pretty sure you cant do this
in ANSI C either).
What you can do is pass the address of a function to another function
and call that function:
int runAfunct( myfunct )
int (*myfunct)();
{
(*myfunct)();
}
int someFunct()
{
return 10;
}
main()
{
int i;
i = runAfunct( someFunct );
printf( "%d\n", i );
exit( 0 );
}
Hope this helps!!!
+=-=-=-=-=-=-=-=-= "... and miles to go before I sleep." -=-=-=-=-=-=-=-=-=-+
| Brad Appleton | Harris Computer Systems Division |
| | 2101 West Cypress Creek Road |
| brad at ssd.csd.harris.com | Fort Lauderdale, FL 33309 USA |
| ... {uunet | novavax}!hcx1!brad | MailStop 161 (305) 973-5007 |
+=-=-=-=-=-=-=-=- DISCLAIMER: I said it, not my company! -=-=-=-=-=-=-=-=-=-+
More information about the Comp.lang.c
mailing list