• Advertisement
Sign in to follow this  

Condition testing

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