Error codes

E0038: bitwise operator mixed with a comparison without parentheses

In a terminal: auk explain E0038 prints this page.

On this page

C and its descendants read x & 1 == 0 as x & (1 == 0), because &, | and ^ bind more loosely than comparisons there; Rust and Python read it as (x & 1) == 0. Rather than pick one and let half of its readers misread the code, Auk requires parentheses whenever &, | or ^ is an operand of ==, !=, <, <=, > or >=. Shifts (<<, >>) mean the same in every language and need none.

Wrong#

auk
fn is_even(x: int): bool = x & 1 == 0

Fixed#

auk
fn is_even(x: int): bool = (x & 1) == 0

Common causes#

  • Testing a flag: write (flags & READ) != 0.
  • Comparing a masked value: (b & 0xc0) == 0x80.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page