What is the easiest way to know whether a certain chunk of code will be optimized in a certain way, in Visual Studio?
For example, the line marked below is very likely to be optimized out.
int main(){
int a=3; //####
std::cout<<"1234"<<std::endl;
}
This can be checked moderately easily by setting a break-point, it will be grey-out.
What if the code is more complex?
Below are just examples.
It would be ideal if I can know it without compiling.
Example 1
int f1(){
return 3;
}
int main(){
int a=f1(); //#### likely to be in-line ?
std::cout<<a<<std::endl;
}
How can I be sure about that f() will be in-line?
Example 2
void f2(bool a){
if(a) std::cout<<"T"<<std::endl;
else std::cout<<"F"<<std::endl;
}
int main(){
f2(true);
f2(false);
}
How can I know whether f2() will be optimized by split into 2 functions like this:-
void f2_true(){ std::cout<<"T"<<std::endl; }
void f2_false(){ std::cout<<"F"<<std::endl; }
int main(){
f2_true();
f2_false();
}