A question on nature of generated assembly in C++ and code Algebra
- by Reetesh Mukul
I wrote this code:
#include <iostream>
int main()
{
int a;
std::cin >> a;
if(a*a== 3){
std::cout << a;
}
return 0;
}
On MSVC I turned ON all optimization flags. I expected that since a*a can never be 3, so compiler should not generate code for the section:
if(a*a== 3){
std::cout << a;
}
However it generated code for the section. I did not check GCC or LLVM/CLang.
What are the limits of expectation from a C++ compiler in these scenarios?