Mail Archives: djgpp/1998/02/24/10:49:09
Thomas Womack <mert0236 AT sable DOT ox DOT ac DOT uk> wrote in article
<6c7u5l$mub$2 AT news DOT ox DOT ac DOT uk>...
> [iC] (jan AT narvik DOT crosswinds DOT net) wrote:
[snip]
> Wouldn't it be easier, and not discernably slower, to put
>
> int nextthink;
>
> nextthink=THINKER_RUN;
> nextthink=THINKER_ATTACK;
>
> switch nextthink
> {
> case THINKER_RUN:
> run();
>
> case THINKER_ATTACK:
> attack();
> }
>
> Tom
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.
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.
--
James E Fisher, C++ Tools Programmer, Team 17 Software Ltd
http://www.team17.com http://www.geocities.com/SiliconValley/Lakes/5639
- Raw text -