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="Keith Thompson, post: 4214685"] You do? The point was to avoid differing branches depending on differing values of a, b, and c. In the if() form, the branches are, in some sense, even more explicit than in the && form. The problem is that the C language defines *behavior*, and you're trying to control the manner in which that behavior is created, i.e., the sequence of machine-level operations. There's no 100% reliable way to do that. Of course you're going to have *some* inconsistent branching; depending on the values of a, b, and c, each thread will or will not execute the body of the if statement. So you're trying to minimize the possible differences in branching. I think your best bet is probably to try a few possible solutions and examine the generated assembly or machine language for each one. If the compiler knows that branching is expensive, it might optimize if (a && b && c) into straight-line code. That's assuming b and c have no side effects, which you can guarantee by storing their values in temporary variables. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Short-circuiting in C
Top