Mail Archives: djgpp/1998/09/27/15:06:45
>I have a little program I have
>writen to decode something but
>most of the program is taken up
>with:
>
>if (x==1) do...
>if (x==2) do...
>if (x==3) do...
>if (x==4) do...
>if (x==5) do...
>etc...
>That goes on for about 40 lines.
>Is there a way to do it quicker
>that would mean less messing
>about for the CPU?
Without question, the best tradeoff between ultimate speed and ultimate
code organization in C/C++ for such a scenatio, is to rewrite your code
thusly:
1. Functionize all the if procesures.
2. Build an array of pointers to function organized by #, such that if
you wanted to call the function for X==1, funclist[1] would be *f().
3. Do this: "f[X](args);". boom!
4. or something like this, i've never actually needed to go this far
yet. But I have seen it done.
--opr
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
- Raw text -