Jump to content
  • Advertisement
Sign in to follow this  
Endar

Condition testing

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

When I have a condition such as: if( something && another == one_more || something_else ) Will the compiler test 'something', and finding it to be 0, would it stop testing the rest of the condition? So, if it was "if( something && veryLargeLongRunningFunction() )", would the function run every single time?

Share this post


Link to post
Share on other sites
Advertisement
Assuming C++, && and || are short circuit operators. If the first part can determine the resut of the expression, then it won't evaluate the rest of the expression. However, this is only true for the built in && and || operators. If you overload || or && for a type then it will evaluate the whole thing.

Share this post


Link to post
Share on other sites
It will skip "another == one_more", but will check something_else.

If it was "if( something && veryLargeLongRunningFunction() )", the function would only be run if something was true.

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!