同一函数的两个版本如何不同,它们的不同之处仅在于一个是内联函数而另一个不是内联函数?这是我今天编写的一些代码,我不确定它如何工作。
#include <cmath>
#include <iostream>
bool is_cube(double r)
{
return floor(cbrt(r)) == cbrt(r);
}
bool inline is_cube_inline(double r)
{
return floor(cbrt(r)) == cbrt(r);
}
int main()
{
std::cout << (floor(cbrt(27.0)) == cbrt(27.0)) << std::endl;
std::cout << (is_cube(27.0)) << std::endl;
std::cout << (is_cube_inline(27.0)) << std::endl;
}
我希望所有输出都等于1,但实际上输出了此值(g ++ 8.3.1,没有标志):
1
0
1
代替
1
1
1
编辑:clang ++ 7.0.0输出此:
0
0
0
和g ++ -Ofast this:
1
1
1