小编cfy*_*cfy的帖子

clang无限尾递归优化

#include <iostream> 

int foo(int i){ 
     return foo(i + 1);
} 

int main(int argc,char * argv[]){ 
     if(argc != 2){ 
         return 1; 
     } 
     std::cout << foo(std::atoi(argv[1])) << std::endl; 
} 
Run Code Online (Sandbox Code Playgroud)

%clang ++ -O2 test.cc

%time./ a.out 42

1490723512

./a.out 42 0.00s用户0.00s系统69%cpu 0.004总计

%time./ a.out 42

1564058296

./a.out 42 0.00s用户0.00s系统56%cpu 0.006总计

%g ++ -O2 test.cc

%./ a.out 42 #infinte递归

^ C

% clang++ --version 
clang version 3.3 (tags/RELEASE_33/final) 
Target: x86_64-apple-darwin12.4.0 
Thread model: posix 
% g++ --version 
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build …
Run Code Online (Sandbox Code Playgroud)

c++ tail-recursion clang++

1
推荐指数
1
解决办法
963
查看次数

标签 统计

c++ ×1

clang++ ×1

tail-recursion ×1