Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Short-circuiting in C
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Eric Sosman, post: 4214613"] You will take one branch if a or b or c is zero, none if all are nonzero. You will never take more than one branch. So no rearrangement can help unless a branch-not-taken has significant cost. If it's still worth proceeding, consider replacing && with &: if (a & b & c) ... This is not quite equivalent to the original, because it can only work with integer operands and only then if a,b,c have suitable values (consider 1,7,32, for example). But you can fix that: if ((a != 0) & (b != 0) & (c != 0)) ... or more briefly: if ( !(!a | !b | !c)) ... or if you find that hard to read: if (!!a & !!b & !!c) ... Of course, the question of what all these alternatives compile to and which is fastest in your particular situation is something that you'll have to answer yourself, preferably by measurement. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Short-circuiting in C
Top