Question: If I have a method call in a for loop that is the same for all iterations of the loop - is the compiler smart enough to optimize it?

```
 for (int j = 0; j < 24; j++ ) {
        *destinationPointer++ = identityArray[j] * (1 / powf(2, valueFromAboveInMethod));
 }     

```

Or should I be explicit and assign it to a value before the loop?

```
 float value = 1 / powf(2, valueFromAboveInMethod);

 // populate the array
 for (int j = 0; j < 24; j++ ) {
        *destinationPointer++ = identityArray[j] * value;
 }     

```

I'd be happier if the compiler did something awesome here and I didn't have to use the 4 bytes for the float - this is inside a recursive method.

Answer: 
It depends on with what options do you compile it. Usually even with minimal optimization enabled compilers deal with such simple optimizations, however it's better to just do it yourself as you have written in the second code. Anyway if compiler will optimize it, it will keep `additional 4 bytes` too, because value need to be stored anywhere.
The compiler may not be smart enough to realize powf is stateless.

When in doubt, compile to assembler and check it yourself.