Discussion:
parser bug?
Charles Hixson via Digitalmars-d-learn
2014-10-23 18:15:14 UTC
Permalink
The code:
void go (ulong recNum)
{ assert (buf[0] == (fh.sizeof + recNo * buf.length) & 0x7f);
if (dirty)
yields the error message:
ells$ dmd test.d
test.d(78): Error: buf[0] == fh.sizeof + recNo * buf.length must be
parenthesized when next to operator &

And I'll swear it looks parenthesized to me.

void go (ulong recNum)
{ ubyte tst = (fh.sizeof + recNo * buf.length) & 0x7f;
assert (buf[0] == tst);
if (dirty)

compiles without error.

Any idea what's going on?
anonymous via Digitalmars-d-learn
2014-10-23 18:40:59 UTC
Permalink
On Thursday, 23 October 2014 at 18:15:26 UTC, Charles Hixson via
Post by Charles Hixson via Digitalmars-d-learn
void go (ulong recNum)
{ assert (buf[0] == (fh.sizeof + recNo * buf.length) &
0x7f);
if (dirty)
ells$ dmd test.d
test.d(78): Error: buf[0] == fh.sizeof + recNo * buf.length
must be parenthesized when next to operator &
And I'll swear it looks parenthesized to me.
The expression is of the form `a == b & c`. You must parenthesize
either `a == b` or `b & c`, making it `(a == b) & c` or `a == (b
& c)`.
ketmar via Digitalmars-d-learn
2014-10-23 21:07:05 UTC
Permalink
On Thu, 23 Oct 2014 11:15:14 -0700
Charles Hixson via Digitalmars-d-learn
Post by Charles Hixson via Digitalmars-d-learn
void go (ulong recNum)
{ assert (buf[0] == (fh.sizeof + recNo * buf.length) & 0x7f);
if (dirty)
ells$ dmd test.d
test.d(78): Error: buf[0] == fh.sizeof + recNo * buf.length must be
parenthesized when next to operator &
And I'll swear it looks parenthesized to me.
void go (ulong recNum)
{ ubyte tst = (fh.sizeof + recNo * buf.length) &
0x7f; assert (buf[0] == tst);
if (dirty)
compiles without error.
Any idea what's going on?
dmd wants this: `((fh.sizeof + recNo * buf.length) & 0x7f)`. it doesn't
like 'a == b&c', 'cause this can be the source of troubles introduced
by simple typo, for example (uses wants `a == b && c`) or something. so
it want you to prove your will. ;-)

Continue reading on narkive:
Loading...