Jump to content
  • Advertisement
Sign in to follow this  
scratt

Conditionally calling function via pointer?

This topic is 3535 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

If I have a function pointed to by void (*foo)(void) and I want to only call it if it's not pointing to NULL how would I go about it? i.e. if(foo) foo(); Obviously the above does not work, but I can't find an example of how to wrangle it to work. Thanks for any help. Scratch that.. if(foo) foo(); appears to work. I was trying if(foo())foo();

Share this post


Link to post
Share on other sites
Advertisement
yeah that should work, my only suggestion is to make sure you initialize it to NULL to be safe. If its global its set to 0 by the compiler, but its good practice to do it yourself anyway.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!