From: wivey AT ix DOT netcom DOT com (William H. Ivey) Newsgroups: comp.lang.c++,comp.os.msdos.djgpp,rec.games.programmer Subject: Re: pointer to function ?? Date: 25 Feb 1998 00:32:24 GMT Organization: Netcom Lines: 25 Message-ID: <6cvoqo$pj2@sjx-ixn11.ix.netcom.com> References: <6c7ltq$ms1$1 AT o DOT online DOT no> <6c7u5l$mub$2 AT news DOT ox DOT ac DOT uk> <01bd4107$bba0dc60$77111111 AT jfisher DOT team17 DOT com> NNTP-Posting-Host: aus-tx18-16.ix.netcom.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In <01bd4107$bba0dc60$77111111 AT jfisher DOT team17 DOT com> "James E Fisher" writes: > >The first idea of a pointer to the code is the fastest way as there is >only one call to the required function (after the address of the >function has been fetched). Using a SWITCH statement is slower as it >can end up as a list of IF() statements by the compiler. Actually, if the switch contains more than a few case statements, it will probably end up as a table of some sort. (In the simplest case, where the key value can be manipulated into an index, a switch is pretty darn fast.) But, you're right, where appropriate, a function pointer is faster. >You also need to think about debugging. Using the pointer to a >function is much cleaner to debug than having to wade through switch >statements. Only if your debugger can resolve the current contents of the pointer into a meaningful function name for you. Otherwise, the switch is clearer - you can put a break point in every case and see which one gets called.-Wm