Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Operators in C and C++
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Criticism of bitwise and equality operators precedence=== The precedence of the bitwise logical operators has been criticized.<ref name="Bell">{{Citation | url = https://www.bell-labs.com/usr/dmr/www/chist.html | title = C history Β§ Neonatal C| publisher = Bell labs}}.</ref> Conceptually, & and | are arithmetic operators like * and +. The expression {{cpp|1=a & b == 7}} is syntactically parsed as {{cpp|1=a & (b == 7)}} whereas the expression {{cpp |1=a + b == 7}} is parsed as {{cpp|1=(a + b) == 7}}. This requires parentheses to be used more often than they otherwise would. Historically, there was no syntactic distinction between the bitwise and logical operators. In [[BCPL]], [[B (programming language)|B]] and early C, the operators {{cpp|&& {{!!}}}} didn't exist. Instead {{cpp|& {{!}}}} had different meaning depending on whether they are used in a 'truth-value context' (i.e. when a Boolean value was expected, for example in {{cpp|1= if (a==b & c) {...} }} it behaved as a logical operator, but in {{cpp|1= c = a & b}} it behaved as a bitwise one). It was retained so as to keep [[backward compatibility]] with existing installations.<ref>{{cite web|url=https://www.perlmonks.org/?node_id=1159769|title=Re^10: next unless condition|website=www.perlmonks.org|access-date=23 March 2018}}</ref> Moreover, in C++ (and later versions of C) equality operations, with the exception of the three-way comparison operator, yield [[Boolean data type|bool]] type values which are conceptually a single bit (1 or 0) and as such do not properly belong in "bitwise" operations.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)