作者cargod (证证)
看板Programming
标题[问题] 请问这个code为何超过64000就会出错
时间Tue Apr 28 22:43:01 2015
#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",×);
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://webptt.com/cn.aspx?n=bbs/Programming/M.1430232184.A.EBC.html
1F:→ MOONRAKER: 手机输入程式 算你狠 218.161.46.90 04/28 22:49
2F:→ pika0923: 感觉像是函式堆叠过深的问题 61.149.208.238 04/28 23:23
3F:→ cargod: 请问解决方式 我用的开发软体是 visual s140.115.204.104 04/28 23:33
4F:→ cargod: tudio 2010140.115.204.104 04/28 23:33
5F:→ pika0923: 堆叠过深就改写成回圈吧 61.149.208.238 04/28 23:50
6F:→ cargod: 可是要求用recursive写== 111.70.48.237 04/29 00:13
7F:→ suhorng: stackoverflow.com/questions/2556938/ 220.137.19.30 04/29 00:31
8F:推 mars90226: C++也能这样改stack size? 1.171.152.88 04/29 02:16
9F:嘘 cancelpc: 递回太深, 超过堆叠大小 61.230.123.238 04/29 09:48
10F:推 littleshan: 把return 0拿掉,改成回传void 60.250.32.97 04/29 10:08
11F:→ littleshan: gcc -O2会使用TCO把它转换成loop 60.250.32.97 04/29 10:09
12F:→ littleshan: VC我就不知道了,你可以自己试试 60.250.32.97 04/29 10:09
13F:推 bxxl: 用tail recursion的写法有帮助吗? 118.160.235.74 04/30 15:36
14F:推 Killercat: 仔细看了一下code 这个是MC++ 59.124.251.135 05/05 12:47
15F:→ Killercat: 可能要看CLI VM怎麽实作的了.... 59.124.251.135 05/05 12:47
16F:→ Killercat: 不过这个改一下main签名就变合法C++了 59.124.251.135 05/05 12:53
17F:推 Killercat: 不过我刚刚发现 LLVM 6.1下 59.124.251.135 05/05 13:10
18F:→ Killercat: 即使z仍然有return 0, TCO仍然生效 59.124.251.135 05/05 13:10