From: karl@grebyn.com (Karl Nyberg)
Subject: Re: Question about Ada expressions
Date: 12 Oct 89 23:37:42 GMT [thread overview]
Message-ID: <8910122337.AA06188@grebyn.com> (raw)
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 --
next reply other threads:[~1989-10-12 23:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1989-10-12 23:37 Karl Nyberg [this message]
1989-10-15 20:35 ` Question about Ada expressions Scott Simpson
-- strict thread matches above, loose matches on Subject: below --
1989-10-06 12:50 Re^2: Ada 9X objectives Robert Munck
1989-10-08 17:07 ` William Thomas Wolfe, 2847
1989-10-11 18:13 ` Dick Dunn
1989-10-11 22:14 ` Question about Ada expressions Perry Schmidt
1989-10-12 10:56 ` STEPHEN D. STRADER
1989-10-12 12:15 ` Robert Firth
1989-10-12 22:07 ` stt
1989-10-13 14:38 ` horst
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox