本文介绍了导致堆栈溢出的最短代码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为纪念Stack Overflow的公开发布,导致堆栈溢出的最短代码是什么?任何语言的欢迎.

To commemorate the public launch of Stack Overflow, what's the shortest code to cause a stack overflow? Any language welcome.

ETA:请明确说明这个问题,因为我是Scheme的偶尔用户:尾部调用递归"实际上是迭代,并且可以由一个不错的编译器相对轻松地将其转换为迭代解决方案的任何解决方案不会被计算在内. :-P

ETA: Just to be clear on this question, seeing as I'm an occasional Scheme user: tail-call "recursion" is really iteration, and any solution which can be converted to an iterative solution relatively trivially by a decent compiler won't be counted. :-P

ETA2:我现在选择了最佳答案";有关原理,请参见这篇文章.感谢所有贡献者! :-)

ETA2: I've now selected a "best answer"; see this post for rationale. Thanks to everyone who contributed! :-)

推荐答案

所有这些答案都没有Befunge吗?我敢打赌,这是所有解决方案中最短的解决方案:

All these answers and no Befunge? I'd wager a fair amount it's shortest solution of them all:

1

不开玩笑.自己尝试: http://www.quirkster.com/iano/js/befunge. html

Not kidding. Try it yourself: http://www.quirkster.com/iano/js/befunge.html

我想我需要解释一下这一点. 1操作数将1压入Befunge的内部堆栈,并且由于缺少其他任何条件,它在语言规则下处于循环状态.

I guess I need to explain this one. The 1 operand pushes a 1 onto Befunge's internal stack and the lack of anything else puts it in a loop under the rules of the language.

使用提供的解释器,您最终会-我最终是最终 –碰到了一个点,在该点上,代表Befunge堆栈的Javascript数组变得太大,以至于浏览器无法重新分配.如果您有一个简单的Befunge解释器,且堆栈较小且有界,就像下面的大多数语言一样,则该程序将更快地引起更明显的溢出.

Using the interpreter provided, you will eventually--and I mean eventually--hit a point where the Javascript array that represents the Befunge stack becomes too large for the browser to reallocate. If you had a simple Befunge interpreter with a smaller and bounded stack--as is the case with most of the languages below--this program would cause a more noticeable overflow faster.

这篇关于导致堆栈溢出的最短代码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 03:51