Do compilers make unnecessary parentheses

For example, if I compile this in Java in Eclipse

intvar = (int)(((var1 * var3))*(7));

the compiler will clear it before

intvar = (int) var1 * var3 * 7;

and then the compiler will do everything possible to turn it into machine code and stuff.

Or do I need to do something special for the compiler to optimize the code?

Also, does this apply to all other languages ​​that are compiled?

+4
source share
4 answers

. . , , . , "" , , (, - , ).

+2

Java . - . .

+5

- javap -c:

intvar = (int)(((var1 * var3))*(7));

:

   4: iload_1       
   5: iload_2       
   6: imul          
   7: bipush        7
   9: imul          
  10: istore_3      

intvar = (int) var1 * var3 * 7;

:

   4: iload_1       
   5: iload_2       
   6: imul          
   7: bipush        7
   9: imul          
  10: istore_3      

. .

+5

. , JLS , , .

,

intvar = (int)((var1*(var2*7)))

, -.

+2

Source: https://habr.com/ru/post/1533091/


All Articles