• Advertisement
Sign in to follow this  

Conditionally calling function via pointer?

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