﻿# V564\. The '&' or '\|' operator is applied to bool type value\. Check for missing parentheses or use the '&&' or '\|\|' operator\.

The analyzer detected a potential error: operators '&' and '\|' handle bool\-type values\. Such expressions are not necessarily errors but they usually signal misprints or condition errors\.

Consider this sample:

```cpp
int a, b;
#define FLAG 0x40
...
if (a & FLAG == b)
{
}
```

This example is a classic one\. A programmer may be easily mistaken in operations' priorities\. It seems that computing runs in this sequence: "\(a & FLAG\) \=\= b"\. But actually it is "a & \(FLAG \=\= b\)"\. Most likely, it is an error\.

The analyzer will generate a warning here because it is odd to use the '&' operator for variables of int and bool types\.

If it turns out that the code does contain an error, you may fix it the following way:

```cpp
if ((a & FLAG) == b)
```

Of course, the code might appear correct and work as it was intended\. But still you'd better rewrite it to make it clearer\. Use the && operator or additional brackets:

```cpp
if (a && FLAG == b)
if (a & (FLAG == b))
```

The V564 warning will not be generated after these corrections are done while the code will get easier to read\.

Consider another sample:

```cpp
#define SVF_CASTAI 0x00000010
if ( !ent->r.svFlags & SVF_CASTAI ) {
  ...
}
```

Here we have an obvious error\. It is the "\!ent\-\>r\.svFlags" subexpression that will be calculated at first and we will get either true of false\. But it does not matter: whether we execute "true & 0x00000010" operation or "false & 0x00000010" operation, the result will be the same\. The condition in this sample is always false\.

This is the correct code:

```cpp
if ( ! (ent->r.svFlags & SVF_CASTAI) )
```



Note\. The analyzer will not generate the warning if there are bool\-type values to the left and to the right of the '&' or '\|' operator\. Although such code does not look too smart, still it is correct\. Here is a code sample the analyzer considers safe:

```cpp
bool X, Y;
...
if (X | Y)
{ ... }
```