From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_05,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!grebyn.com!karl From: karl@grebyn.com (Karl Nyberg) Newsgroups: comp.lang.ada Subject: Re: Question about Ada expressions Message-ID: <8910122337.AA06188@grebyn.com> Date: 12 Oct 89 23:37:42 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet List-Id: I had a friend call yesterday after spending five hours trying to figure out why some C code didn't work based on this expression: if (variable & MASK == VALUE) He mistook the rules of precedence, just as Robert Firth expressed it in his response. The K&R book explains this reasoning: Note that the precedence of the bitwise logical operators &, ^ and | falls below == (test for equality) and != (test for inequality). This implies that bit-testing expressions like if ((x & MASK) == 0) ... must be fully parenthesized to give proper results. [p. 49] Seems like it was kind of the Ada designers to preclude this from the language. Getting an error during compile time would have saved my friend immense difficulty. Getting a manual might have helped him, too... -- Karl --