Does the C ++ compiler use different solutions for nesting two different calls for the same inline function?
consider this code:
inline func(int x) {
return x + (x << 1) + (x << 2) + (x << 3) + (x << 4);
}
int main() {
int y = func(1) + func(2) + func(3) + func(4);
for(int i = 0; i < 100000000; ++i)
y += func(i % 10);
cout << y << endl;
return 0;
}
will the compiler perform the same action with calls before the loop and inside the loop? if we consider the length of the code along with speed optimization, then the calls before the loop should not be built in, but inside should be.
source
share