Path: chuka.playstation.co.uk!news From: Phil Gooch Newsgroups: scee.yaroze.freetalk.english Subject: Re: Question for the C experts Date: Fri, 04 Sep 1998 13:30:54 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 52 Message-ID: <35EFDD7D.6A5038F6@easynet.co.uk> References: <35EEB905.940C6E98@ndirect.co.uk> NNTP-Posting-Host: 193.131.140.246 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.05 [en] (Win95; I) Alex Herbert wrote: > In my days of 68000 programming, I used to make tables of sub-routine > addresses so I could jump to them using an index - a bit like the old > ON..GOSUB.. in BASIC. > > I'm now using: > > switch(f) { > case 0: > function0(); > break; > case 1: > function1(); > break; > > etc. etc. > } > > which is not very efficient, especially if there are >20 functions. > > Is there any way I can hold a table of pointers to the functions and > call them using an index? If so, could someone give me an example of > the declarations required, and the call itself. > > Thanx. > > Herbs Blimey! Here's a question I can answer! Tho' I dare say you've had a few better replies by now. For a simple group of functions that take no arguments and return no value, you set up an array of pointers to functions: void (*menu[NUM_MENUS])(void) = {menu1, menu2, menu3...} // up to NUM_MENUS then you call your selected function by doing: (*menu[i])(); This will call the i-th function in the array. Cheers Phil