C++ warning: suggest parentheses around arithmetic in operand of |

Programmer picture Programmer · Jun 4, 2010 · Viewed 18.9k times · Source

I have a code like

A = B|C|D|E;

Throwing the warning "suggest parentheses around arithmetic in operand of |"

Expecting that expression needs high priority paranthesis for operators, tried the following ways:

A=(B|C)|(D|E);

one more as :

A=(((B|C)|D)|E);

Still the same warning persists.

Please help me in resolving this.

Thanks, Sujatha

B, C,D are enums and E is an integer.

Answer

Windows programmer picture Windows programmer · Jun 4, 2010

You have some arithmetic operator in your expression that isn't really simply B, or that isn't really simply C, etc. The compiler is suggesting that you parenthesize whichever expression so that readers will see that you wrote what you meant. If you don't parenthesize, everyone has to remember exactly what the priorities are, and they have to figure out if you remembered when you wrote it.

Try this: (B)|(C)|(D)|(E).