www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/24/19:45:51

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

In <01bd4107$bba0dc60$77111111 AT jfisher DOT team17 DOT com> "James E Fisher"
<James DOT Fisher AT team17 DOT com> 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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019