我正在使用gcc 4.6.1并且正在获得一些涉及调用constexpr函数的有趣行为.这个程序运行得很好,直接打印出来12200160415121876738.
#include <iostream>
extern const unsigned long joe;
constexpr unsigned long fib(unsigned long int x)
{
return (x <= 1) ? 1 : (fib(x - 1) + fib(x - 2));
}
const unsigned long joe = fib(92);
int main()
{
::std::cout << "Here I am!\n";
::std::cout << joe << '\n';
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这个程序需要永远运行,我从来没有耐心等待它打印出一个值:
#include <iostream>
constexpr unsigned long fib(unsigned long int x)
{
return (x <= 1) ? 1 : (fib(x - 1) + …Run Code Online (Sandbox Code Playgroud)