看板 Programming 關於我們 聯絡資訊
#include "stdafx.h" #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <time.h> int z(char* ,int); int main(array<System::String ^> ^args) { clock_t t1, t2; char arr[1000]; int times; printf("input="); gets(arr); printf("times="); scanf("%d",&times); t1 = clock(); z(&arr[0] , times); t2 = clock(); printf("\n------%lf\n", (t2-t1)/(double)(CLOCKS_PER_SEC)); system("pause"); return 0; } int z(char* arr, int times) { static int c = 1; printf("%s",arr); c++; if(c<=times){ z(&arr[0],times); } return 0; } 手機排版請見諒 -- Sent from my Android -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.115.204.104 ※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1430232184.A.EBC.html
MOONRAKER: 手機輸入程式 算你狠 218.161.46.90 04/28 22:49
pika0923: 感覺像是函式堆疊過深的問題 61.149.208.238 04/28 23:23
cargod: 請問解決方式 我用的開發軟體是 visual s140.115.204.104 04/28 23:33
cargod: tudio 2010140.115.204.104 04/28 23:33
pika0923: 堆疊過深就改寫成迴圈吧 61.149.208.238 04/28 23:50
cargod: 可是要求用recursive寫== 111.70.48.237 04/29 00:13
suhorng: stackoverflow.com/questions/2556938/ 220.137.19.30 04/29 00:31
mars90226: C++也能這樣改stack size? 1.171.152.88 04/29 02:16
cancelpc: 遞迴太深, 超過堆疊大小 61.230.123.238 04/29 09:48
littleshan: 把return 0拿掉,改成回傳void 60.250.32.97 04/29 10:08
littleshan: gcc -O2會使用TCO把它轉換成loop 60.250.32.97 04/29 10:09
littleshan: VC我就不知道了,你可以自己試試 60.250.32.97 04/29 10:09
bxxl: 用tail recursion的寫法有幫助嗎? 118.160.235.74 04/30 15:36
Killercat: 仔細看了一下code 這個是MC++ 59.124.251.135 05/05 12:47
Killercat: 可能要看CLI VM怎麼實作的了.... 59.124.251.135 05/05 12:47
Killercat: 不過這個改一下main簽名就變合法C++了 59.124.251.135 05/05 12:53
Killercat: 不過我剛剛發現 LLVM 6.1下 59.124.251.135 05/05 13:10
Killercat: 即使z仍然有return 0, TCO仍然生效 59.124.251.135 05/05 13:10