Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Digitalfragment

Function pointer speed

This topic is 5506 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

quote:
Original post by andy_fish
some famous & smart guy one said that premature optimization is the root of all evil


And another smart guy said that the best optimization was the one that took you from a non-working program to a working program.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
Advertisement
how would u implement function pointers that would act like a switch? how could you resolve which function pointer points to another function at runtime? wouldn''t you need a switch or if-else to do that?

Share this post


Link to post
Share on other sites
quote:
Original post by Alpha_ProgDes
how would u implement function pointers that would act like a switch? how could you resolve which function pointer points to another function at runtime? wouldn't you need a switch or if-else to do that?



int foo( int );
int bar( int );
int baz( int );
int quux( int );

typedef int (*func_ptr_type)( int );
enum eFunc { eFoo, eBar, eBaz, eQuux }
func_ptr_type funcTable[] = { foo, bar, baz, quux };

int Switch( eFunc which, int arg )
{
return funcTable[which](arg)
}


No conditionals needed.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]


[edited by - Fruny on September 24, 2003 4:14:32 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!