Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uflorida!novavax!hcx1!brad From: brad@SSD.CSD.HARRIS.COM (Brad Appleton) Newsgroups: comp.lang.c Subject: Re: Passing functions in C Summary: pass the address, *not* the name Message-ID: <3242@hcx1.SSD.CSD.HARRIS.COM> Date: 12 Mar 90 17:13:32 GMT References: <1990Mar9.045151.9601@ucselx.sdsu.edu> Sender: news@hcx1.SSD.CSD.HARRIS.COM Distribution: usa Organization: Harris Computer Systems, Fort Lauderdale, FL Lines: 69 Sorry to post this folks! I tried e-mail to both of her addresses but both bounced :-( In article <1990Mar9.045151.9601@ucselx.sdsu.edu> cynthia@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 > >or > > >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@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! -=-=-=-=-=-=-=-=-=-+