Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #28333
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Joshua Cranmer đ§ <Pidgeot18@verizon.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: verifying precedence |
| Date | Thu, 01 May 2014 10:35:34 -0500 |
| Organization | A noiseless patient Spider |
| Lines | 52 |
| Message-ID | <ljtpkp$isn$1@dont-email.me> (permalink) |
| References | <ivc4m95b309smq7g0pkes96cfpmdfsmj6q@4ax.com> <AfOdnQTUOv31pf_OnZ2dnUVZ8tednZ2d@giganews.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Thu, 1 May 2014 15:35:53 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="8b6ddcc38ecbed2f71b30fabadb8aa0b"; logging-data="19351"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/1gY7kv1IQOt7EhU+vrajWPdR8l1uLPc=" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Thunderbird/29.0 |
| In-Reply-To | <AfOdnQTUOv31pf_OnZ2dnUVZ8tednZ2d@giganews.com> |
| Cancel-Lock | sha1:EthJYrK4uNM7bEq6Z9XIRC9+mKo= |
| Xref | csiph.com comp.lang.java.programmer:28333 |
Show key headers only | View raw
On 5/1/2014 7:04 AM, Leif Roar Moldskred wrote: > Roedy Green <see_website@mindprod.com.invalid> wrote: >> >> You could consult a precedence table, but you could misinterpret it. >> Java's rules of precedence and association are quite complicated. >> > > "Practical Programming in C" summed up the precedence rules in C > thusly: > > " Precedence Operator > 1. * / % > 2. + - > > Put parantheses around everything else." > > If the meaning of your code depends on the particulars of operator > precedence beyond the very obvious rules above, rewrite it so that it > doesn't. (The same holds for the difference between ++i and i++.) That's not quite the right rules, but probably because it's ignoring half the operators in the first place. I'd remember it as: 1. Unary operators [includes parentheses] 2. * / % 3. + - 4. Relational (<, >, ==, etc.) 5. Logical (&&, ||) 6. ?: 7. = and op= The position of shift and bitwise operators is the part I can never remember: C (by accident of history [1]) put the bitwise below relational operators instead of above it (so you have to say (x & mask) == mask instead of x & mask == mask). Some descendants fixed the issue, while others did not, so as someone who regularly uses several different languages, I can never remember if the language I'm in fixed the precedence or not. Note that the table I give glides over the binding of a few operators (x++ and ++x are different levels, as are < and ==), but in terms of remembering where I need to put parentheses, it's sufficient. [1] Logical, short-circuit and and or came much later. That's why the and pseudo-keyword maps to &, not &&. Arguably, when the logical operators had been introduced, the bitwise operators ought to have been moved in precedence, but maybe the authors of C didn't want to risk such a breaking change at that time. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
verifying precedence Roedy Green <see_website@mindprod.com.invalid> - 2014-05-01 04:50 -0700
Re: verifying precedence leif.roar@invalid.com (Leif Roar Moldskred) - 2014-05-01 07:04 -0500
Re: verifying precedence Joshua Cranmer đ§ <Pidgeot18@verizon.invalid> - 2014-05-01 10:35 -0500
Re: verifying precedence Joerg Meier <joergmmeier@arcor.de> - 2014-05-01 17:40 +0200
Re: verifying precedence Joshua Cranmer đ§ <Pidgeot18@verizon.invalid> - 2014-05-01 10:49 -0500
Re: verifying precedence Joshua Cranmer đ§ <Pidgeot18@verizon.invalid> - 2014-05-01 17:05 -0500
Re: verifying precedence Gene Wirchenko <genew@telus.net> - 2014-05-02 10:22 -0700
Re: verifying precedence "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2014-05-04 10:53 +0100
Re: verifying precedence Simon Lewis <simonlewis2001@gmail.com> - 2014-05-04 13:23 +0200
Re: verifying precedence Arne VajhĂžj <arne@vajhoej.dk> - 2014-05-01 18:51 -0400
Re: verifying precedence Arne VajhĂžj <arne@vajhoej.dk> - 2014-05-01 19:00 -0400
Re: verifying precedence Roedy Green <see_website@mindprod.com.invalid> - 2014-05-01 17:48 -0700
Re: verifying precedence Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-05-02 13:29 -0400
Re: verifying precedence Arne VajhĂžj <arne@vajhoej.dk> - 2014-05-01 18:50 -0400
Re: verifying precedence Arne VajhĂžj <arne@vajhoej.dk> - 2014-05-01 19:18 -0400
Re: verifying precedence Roedy Green <see_website@mindprod.com.invalid> - 2014-05-01 17:46 -0700
Re: verifying precedence Arne VajhĂžj <arne@vajhoej.dk> - 2014-05-01 21:27 -0400
csiph-web