하나는 인라인이고 다른 하나는 아닌 동일한 함수의 두 버전이 어떻게 다른 값을 반환 할 수 있습니까? 오늘 작성한 코드가 있는데 어떻게 작동하는지 잘 모르겠습니다.
#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