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
| vs || operator on C99 bool types
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: 4223646"] The only effective difference that I can see is that with | both `a' and `b' are evaluated, while with || the evaluation of `b' is skipped if `a' evaluates to non-zero. In your example, neither `a' nor `b' has side-effects, and the evaluation of `b' does not depend on the truth of `a', so I see no effective difference. Perhaps your discussion partner could favor us with the reasons behind his assertion? I'm sure he has some, and perhaps they'll be convincing. But on the bald evidence of the example at hand, I'd have to dismiss his preference as superstition. You said "C99," did you not? The actual number of bits occupied by a `_Bool' is at the implementation's whim, of course -- it must be at least CHAR_BIT and could be much greater -- but choosing | over || or vice versa wouldn't change it. A guess: Perhaps your discussion partner retains bad memories of a "simulated boolean" from pre-C99 days, and was really concerned with & vs. &&? With a SimulatedBool based on an integer type, you could have SimulatedBool a = 1, b = 2; /* both "true" */ assert (a && b); /* succeeds */ assert (a & b); /* fails */ With actual _Bool instead of SimulatedBool both assertions would succeed. Is that the origin of his prejudice? The standard says -- well, the Standard says a lot. The pieces that seem relevant are those I've summarized above. If others are of importance to your discussion partner, try to elicit them. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
| vs || operator on C99 bool types
Top