Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: | vs || operator on C99 bool types |
| Date | 2011-06-27 21:51 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <iubc4k$3d6$1@dont-email.me> (permalink) |
| References | <20110627162111.12429.65316.XPN@final-memory.org> |
On 6/27/2011 12:21 PM, Matthias Arndt wrote:
> Hello all,
>
> I heard an opinion on the use of the | operator together with C99
> conform bool types (stdbool.h)
>
> My discussion partner stated that
> _Bool a, b;
> ......
> a | b;
>
> should be forbidden and a || b should be used instead.
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.
> I personally can't see the difference for true boolean types (which
> would be *implementation* specific, but let's assume an embedded
> compiler with a true bool type that maps to a real bit.)
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?
> What does the standard say? Are there opinions on this?
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.
--
Eric Sosman
esosman@ieee-dot-org.invalid
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
| vs || operator on C99 bool types Matthias Arndt <marndt@asmsoftware.de> - 2011-06-27 16:21 +0000
Re: | vs || operator on C99 bool types Shao Miller <sha0.miller@gmail.com> - 2011-06-27 13:38 -0400
Re: | vs || operator on C99 bool types Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-27 21:51 -0400
Re: | vs || operator on C99 bool types James Waldby <not@valid.invalid> - 2011-06-28 16:16 +0000
[OT] Genderangement [Was: Re: | vs || operator on C99 bool types] Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-28 20:35 -0400
Re: [OT] Genderangement [Was: Re: | vs || operator on C99 bool types] blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-06-29 21:33 +0000
Re: [OT] Genderangement [Was: Re: | vs || operator on C99 bool types] Michael Press <rubrum@pacbell.net> - 2011-06-30 10:58 -0700
Re: [OT] Genderangement [Was: Re: | vs || operator on C99 bool types] blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-06-30 18:57 +0000
Re: [OT] Genderangement [Was: Re: | vs || operator on C99 bool types] Michael Press <rubrum@pacbell.net> - 2011-07-01 12:53 -0700
Re: [OT] Genderangement [Was: Re: | vs || operator on C99 bool types] blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-02 18:27 +0000
Re: [OT] Genderangement [Was: Re: | vs || operator on C99 bool types] Michael Press <rubrum@pacbell.net> - 2011-07-03 20:53 -0700
Re: | vs || operator on C99 bool types Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-03 03:34 -0700
Re: | vs || operator on C99 bool types James Kuyper <jameskuyper@verizon.net> - 2011-07-03 08:25 -0400
Re: | vs || operator on C99 bool types gordonb.pbl6v@burditt.org (Gordon Burditt) - 2011-07-03 18:23 -0500
Re: | vs || operator on C99 bool types James Kuyper <jameskuyper@verizon.net> - 2011-06-28 07:21 -0400
Re: | vs || operator on C99 bool types James Kuyper <jameskuyper@verizon.net> - 2011-06-28 08:24 -0400
Re: | vs || operator on C99 bool types Matthias Arndt <marndt@asmsoftware.de> - 2011-06-28 16:11 +0000
Re: | vs || operator on C99 bool types Tim Rentsch <txr@alumni.caltech.edu> - 2011-06-28 16:37 -0700
Re: | vs || operator on C99 bool types Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-03 03:41 -0700
Re: | vs || operator on C99 bool types Tim Rentsch <txr@alumni.caltech.edu> - 2011-07-03 15:02 -0700
csiph-web