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

<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</p>

<p>ETA2: I've now selected a “best answer”; see <a href="https://stackoverflow.com/questions/62188/stack-overflow-code-golf/71833#71833">this post</a> for rationale. Thanks to everyone who contributed! :-)</p>

[{'answer_id': 62189, 'author': 'C. K. Young', 'author_id': 13, 'author_profile': 'https://Stackoverflow.com/users/13', 'pm_score': 7, 'selected': False, 'text': '<p>My current best (in x86 assembly) is:</p>\n\n<pre><code>push eax\njmp short $-1\n</code></pre>\n\n<p>which results in 3 bytes of object code (<code>50 EB FD</code>). For 16-bit code, this is also possible:</p>\n\n<pre><code>call $\n</code></pre>\n\n<p>which also results in 3 bytes (<code>E8 FD FF</code>).</p>\n'}, {'answer_id': 62191, 'author': 'Niyaz', 'author_id': 184, 'author_profile': 'https://Stackoverflow.com/users/184', 'pm_score': 0, 'selected': False, 'text': '<p><strong>C++</strong>:</p>\n\n<pre><code>int overflow(int n)\n{\n    return overflow(1);\n}\n</code></pre>\n'}, {'answer_id': 62195, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 6, 'selected': False, 'text': '<p>C#:  </p>\n\n<pre><code>public int Foo { get { return Foo; } }\n</code></pre>\n'}, {'answer_id': 62205, 'author': 'Serafina Brocious', 'author_id': 4977, 'author_profile': 'https://Stackoverflow.com/users/4977', 'pm_score': 4, 'selected': False, 'text': '<p><strong>Python</strong>:</p>\n\n<pre><code>so=lambda:so();so()\n</code></pre>\n\n<p>Alternatively:</p>\n\n<pre><code>def so():so()\nso()\n</code></pre>\n\n<p>And if Python optimized tail calls...:</p>\n\n<pre><code>o=lambda:map(o,o());o()\n</code></pre>\n'}, {'answer_id': 62209, 'author': 'TK.', 'author_id': 1816, 'author_profile': 'https://Stackoverflow.com/users/1816', 'pm_score': 2, 'selected': False, 'text': '<p>PIC18:</p>\n\n<blockquote>\n  <p>overflow</p>\n  \n  <blockquote>\n<pre><code>    PUSH   \n    CALL   overflow \n</code></pre>\n  </blockquote>\n</blockquote>\n'}, {'answer_id': 62213, 'author': 'Agnel Kurian', 'author_id': 45603, 'author_profile': 'https://Stackoverflow.com/users/45603', 'pm_score': 0, 'selected': False, 'text': '<pre><code>int main(){\n    int a = 20;\n    return main();\n}\n</code></pre>\n'}, {'answer_id': 62215, 'author': 'Huppie', 'author_id': 1830, 'author_profile': 'https://Stackoverflow.com/users/1830', 'pm_score': 0, 'selected': False, 'text': '<p><strong>JavaScript:</strong></p>\n\n<pre><code>function i(){ i(); }\ni();\n</code></pre>\n\n<p><hr>\n<strong>C++</strong>\nUsing a function-pointer:</p>\n\n<pre><code>int main(){\n   int (*f)() = &amp;main;\n   f();\n}\n</code></pre>\n'}, {'answer_id': 62217, 'author': 'Vinko Vrsalovic', 'author_id': 5190, 'author_profile': 'https://Stackoverflow.com/users/5190', 'pm_score': 5, 'selected': False, 'text': '<p>In english:</p>\n\n<pre><code>recursion = n. See recursion.\n</code></pre>\n'}, {'answer_id': 62221, 'author': 'Agnel Kurian', 'author_id': 45603, 'author_profile': 'https://Stackoverflow.com/users/45603', 'pm_score': 1, 'selected': False, 'text': '<pre><code>/* In C/C++ (second attempt) */\n\nint main(){\n    int a = main() + 1;\n    return a;\n}\n</code></pre>\n'}, {'answer_id': 62231, 'author': 'C. K. Young', 'author_id': 13, 'author_profile': 'https://Stackoverflow.com/users/13', 'pm_score': 4, 'selected': False, 'text': "<p>Here's my C contribution, weighing in at 18 characters:</p>\n\n<pre><code>void o(){o();o();}\n</code></pre>\n\n<p>This is a <em>lot</em> harder to tail-call optimise! :-P</p>\n"}, {'answer_id': 62233, 'author': 'GateKiller', 'author_id': 383, 'author_profile': 'https://Stackoverflow.com/users/383', 'pm_score': 0, 'selected': False, 'text': '<p>C#, done in 20 characters (exclusing whitespace):</p>\n\n<pre><code>int s(){\n    return s();\n}\n</code></pre>\n'}, {'answer_id': 62243, 'author': 'Serafina Brocious', 'author_id': 4977, 'author_profile': 'https://Stackoverflow.com/users/4977', 'pm_score': 2, 'selected': False, 'text': '<p><strong>CIL/MSIL</strong>:</p>\n\n<pre><code>loop: ldc.i4.0\nbr loop\n</code></pre>\n\n<p>Object code:</p>\n\n<pre><code>16 2B FD\n</code></pre>\n'}, {'answer_id': 62244, 'author': 'GateKiller', 'author_id': 383, 'author_profile': 'https://Stackoverflow.com/users/383', 'pm_score': 7, 'selected': False, 'text': '<p>You could also try this in C#.net</p>\n\n<pre><code>throw new StackOverflowException();\n</code></pre>\n'}, {'answer_id': 62318, 'author': 'stusmith', 'author_id': 6604, 'author_profile': 'https://Stackoverflow.com/users/6604', 'pm_score': 5, 'selected': False, 'text': "<p>How about the following in BASIC:</p>\n\n<pre><code>10 GOSUB 10\n</code></pre>\n\n<p>(I don't have a BASIC interpreter I'm afraid so that's a guess).</p>\n"}, {'answer_id': 62321, 'author': 'Serafina Brocious', 'author_id': 4977, 'author_profile': 'https://Stackoverflow.com/users/4977', 'pm_score': 7, 'selected': False, 'text': '<p><strong>Nemerle</strong>:</p>\n\n<p>This <strong>crashes the compiler</strong> with a StackOverflowException:</p>\n\n<pre><code>def o(){[o()]}\n</code></pre>\n'}, {'answer_id': 62323, 'author': 'dr_bonzo', 'author_id': 6657, 'author_profile': 'https://Stackoverflow.com/users/6657', 'pm_score': 2, 'selected': False, 'text': '<p>Ruby:</p>\n\n<pre><code>def s() s() end; s()\n</code></pre>\n'}, {'answer_id': 62370, 'author': 'C. K. Young', 'author_id': 13, 'author_profile': 'https://Stackoverflow.com/users/13', 'pm_score': 5, 'selected': False, 'text': "<p>I loved Cody's answer heaps, so here is my similar contribution, in C++:</p>\n\n<pre><code>template &lt;int i&gt;\nclass Overflow {\n    typedef typename Overflow&lt;i + 1&gt;::type type;\n};\n\ntypedef Overflow&lt;0&gt;::type Kaboom;\n</code></pre>\n\n<p>Not a code golf entry by any means, but still, anything for a meta stack overflow! :-P</p>\n"}, {'answer_id': 62379, 'author': 'Ozgur Ozcitak', 'author_id': 976, 'author_profile': 'https://Stackoverflow.com/users/976', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Lisp</strong></p>\n\n<pre><code>(defun x() (x)) (x)\n</code></pre>\n'}, {'answer_id': 62399, 'author': 'Andrew Johnson', 'author_id': 5109, 'author_profile': 'https://Stackoverflow.com/users/5109', 'pm_score': 2, 'selected': False, 'text': '<pre><code>a{return a*a;};\n</code></pre>\n\n<p>Compile with:</p>\n\n<pre><code>gcc -D"a=main()" so.c\n</code></pre>\n\n<p>Expands to:</p>\n\n<pre><code>main() {\n    return main()*main();\n}\n</code></pre>\n'}, {'answer_id': 62402, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 1, 'selected': False, 'text': '<p>c# again:</p>\n\n<pre><code>class Foo { public Foo() {new Foo(); } }\n</code></pre>\n'}, {'answer_id': 62407, 'author': 'asksol', 'author_id': 5577, 'author_profile': 'https://Stackoverflow.com/users/5577', 'pm_score': 4, 'selected': False, 'text': '<p>perl in 12 chars:</p>\n\n<pre><code>$_=sub{&amp;$_};&amp;$_\n</code></pre>\n\n<p>bash in 10 chars (the space in the function is important):</p>\n\n<pre><code>i(){ i;};i\n</code></pre>\n'}, {'answer_id': 62412, 'author': 'JosephStyons', 'author_id': 672, 'author_profile': 'https://Stackoverflow.com/users/672', 'pm_score': 1, 'selected': False, 'text': "<p>Complete Delphi program.</p>\n\n<pre><code>program Project1;\n{$APPTYPE CONSOLE}\nuses SysUtils;\n\nbegin\n  raise EStackOverflow.Create('Stack Overflow');\nend.\n</code></pre>\n"}, {'answer_id': 62420, 'author': 'Sean Cameron', 'author_id': 6692, 'author_profile': 'https://Stackoverflow.com/users/6692', 'pm_score': 0, 'selected': False, 'text': '<p>Clarion:</p>\n\n<pre><code>Poke(0)\n</code></pre>\n'}, {'answer_id': 62432, 'author': 'Manrico Corazzi', 'author_id': 4690, 'author_profile': 'https://Stackoverflow.com/users/4690', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Java</strong> (embarassing):</p>\n\n<pre><code>public class SO \n{ \n  private void killme()\n  {\n    killme();\n  }\n\n  public static void main(String[] args) \n  { \n    new SO().killme(); \n  } \n}\n</code></pre>\n\n<p><strong>EDIT</strong>\nOf course it can be considerably shortened:</p>\n\n<pre><code>class SO\n{\n  public static void main(String[] a)\n  {\n    main(null);\n  }\n}\n</code></pre>\n'}, {'answer_id': 62468, 'author': 'Antti Kissaniemi', 'author_id': 2948, 'author_profile': 'https://Stackoverflow.com/users/2948', 'pm_score': 1, 'selected': False, 'text': '<p>so.c in <strong>15 characters</strong>:</p>\n\n<pre><code>main(){main();}\n</code></pre>\n\n<p>Result:</p>\n\n<pre><code>antti@blah:~$ gcc so.c -o so\nantti@blah:~$ ./so\nSegmentation fault (core dumped)\n</code></pre>\n\n<p><strong>Edit</strong>: Okay, it gives warnings with -Wall and does not cause a stack overflow with -O2. But it works!</p>\n'}, {'answer_id': 62568, 'author': 'Alnitak', 'author_id': 6782, 'author_profile': 'https://Stackoverflow.com/users/6782', 'pm_score': 0, 'selected': False, 'text': "<p>I tried to do it in Erlang:</p>\n\n<pre><code>c(N)-&gt;c(N+1)+c(N-1).\nc(0).\n</code></pre>\n\n<p>The double invocation of itself makes the memory usage go up <code>O(n^2)</code> rather than <code>O(n)</code>.</p>\n\n<p>However the Erlang interpreter doesn't appear to manage to crash.</p>\n"}, {'answer_id': 62596, 'author': 'Leo Lännenmäki', 'author_id': 2451, 'author_profile': 'https://Stackoverflow.com/users/2451', 'pm_score': 1, 'selected': False, 'text': '<p><strong>JavaSript:</strong></p>\n\n<p>Huppies answer to one line:</p>\n\n<pre><code>(function i(){ i(); })()\n</code></pre>\n\n<p>Same amount of characters, but no new line :)</p>\n'}, {'answer_id': 62609, 'author': 'Kinjal Dixit', 'author_id': 6629, 'author_profile': 'https://Stackoverflow.com/users/6629', 'pm_score': 0, 'selected': False, 'text': '<p>recursion is old hat.  here is mutual recursion.  kick off by calling either function.</p>\n\n<pre><code>a()\n{\n    b();\n}\nb()\n{\n    a();\n}\n</code></pre>\n\n<p>PS: but you were asking for shortest way.. not most creative way!</p>\n'}, {'answer_id': 62733, 'author': 'Michal', 'author_id': 7135, 'author_profile': 'https://Stackoverflow.com/users/7135', 'pm_score': 1, 'selected': False, 'text': "<p>Java (complete content of X.java):</p>\n\n<pre><code>class X {\npublic static void main(String[] args) {\n    main(null);\n}}\n</code></pre>\n\n<p>Considering all the syntactic sugar, I am wondering if any shorter can be done in Java. Anyone?</p>\n\n<p><strong>EDIT:</strong> Oops, I missed there is already almost identical solution posted.</p>\n\n<p><strong>EDIT 2:</strong> I would say, that this one is (character wise) the shortest possible</p>\n\n<pre><code>class X{public static void main(String[]a){main(null);}}\n</code></pre>\n\n<p><strong>EDIT 3:</strong> Thanks to Anders for pointing out null is not optimal argument, so it's shorter to do:</p>\n\n<pre><code>class X{public static void main(String[]a){main(a);}}\n</code></pre>\n"}, {'answer_id': 62786, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>On the cell spus, there are no stack overflows, so theres no need for recursion, we can just wipe the stack pointer.</p>\n\n<p>asm("andi $1, $1, 0" );</p>\n'}, {'answer_id': 62809, 'author': 'Anders Sandvig', 'author_id': 1709, 'author_profile': 'https://Stackoverflow.com/users/1709', 'pm_score': 3, 'selected': False, 'text': '<p>3 bytes:\n<code><pre>\nlabel:\n  pusha\n  jmp label\n</pre></code></p>\n\n<p><Strong>Update</strong></p>\n\n<p>According to <a href="http://www.penguin.cz/~literakl/intel/c.html#CALL" rel="nofollow noreferrer">the (old?) Intel(?) documentation</a>, this is also 3 bytes:</p>\n\n<p><code><pre>\nlabel:\n  call label\n</pre></code></p>\n'}, {'answer_id': 62917, 'author': 'JWHEAT', 'author_id': 7079, 'author_profile': 'https://Stackoverflow.com/users/7079', 'pm_score': 0, 'selected': False, 'text': "<p><strong>PHP</strong> - recursion just for fun.  I imagine needing a PHP interpreter takes it out of the running, but hey - it'll make the crash.</p>\n\n<pre><code>function a() { a(); } a();\n</code></pre>\n"}, {'answer_id': 62973, 'author': 'shelfoo', 'author_id': 3444, 'author_profile': 'https://Stackoverflow.com/users/3444', 'pm_score': 1, 'selected': False, 'text': "<p>There was a perl one already, but this is a couple characters shorter (9 vs 12) - and it doesn't recurse :)</p>\n\n<blockquote>\n  <p>s//*_=0/e</p>\n</blockquote>\n"}, {'answer_id': 63020, 'author': 'Tim Ring', 'author_id': 3685, 'author_profile': 'https://Stackoverflow.com/users/3685', 'pm_score': 2, 'selected': False, 'text': '<p>GWBASIC output...</p>\n\n<pre><code>OK\n10 i=0\n20 print i;\n30 i=i+1\n40 gosub 20\nrun\n 0  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21\n 22  23  24  25  26  27  28  29  30  31  32  33\nOut of memory in 30\nOk\n</code></pre>\n\n<p>Not much stack depth there :-)</p>\n'}, {'answer_id': 63025, 'author': 'bgee', 'author_id': 7003, 'author_profile': 'https://Stackoverflow.com/users/7003', 'pm_score': 0, 'selected': False, 'text': '<pre><code>//lang = C++... it\'s joke, of course\n//Pay attention how \nvoid StackOverflow(){printf("StackOverflow!");}\nint main()\n{\n    StackOverflow(); //called StackOverflow, right?\n}\n</code></pre>\n'}, {'answer_id': 63061, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 2, 'selected': False, 'text': '<p>F#</p>\n\n<p>People keep asking "What is F# useful for?"  </p>\n\n<pre><code>let rec f n =\n    f (n)\n</code></pre>\n\n<p>performance optimized version (will fail faster :) )</p>\n\n<pre><code>let rec f n =\n    f (f(n))\n</code></pre>\n'}, {'answer_id': 63116, 'author': 'Jesse Millikan', 'author_id': 7526, 'author_profile': 'https://Stackoverflow.com/users/7526', 'pm_score': 1, 'selected': False, 'text': '<p>I have a list of these at <a href="http://www.everything2.com/index.pl?node_id=1904026" rel="nofollow noreferrer">Infinite Loop</a> on E2 - see just the ones indicated as "Stack Overflow" in the title.</p>\n\n<p>I think the shortest there is</p>\n\n<pre><code>[dx]dx\n</code></pre>\n\n<p>in <a href="http://c2.com/cgi/wiki?DeeCee" rel="nofollow noreferrer">dc</a>. There may be a shorter solution in <a href="http://c2.com/cgi/wiki?FalseLanguage" rel="nofollow noreferrer">False</a>.</p>\n\n<p>EDIT: Apparently this doesn\'t work... At least on GNU dc. Maybe it was on a BSD version.</p>\n'}, {'answer_id': 63137, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': -1, 'selected': False, 'text': '<p>Ruby:</p>\n\n<pre><code>def i()i()end;i()\n</code></pre>\n\n<p>(17 chars)</p>\n'}, {'answer_id': 63269, 'author': 'Evan DeMond', 'author_id': 7695, 'author_profile': 'https://Stackoverflow.com/users/7695', 'pm_score': 2, 'selected': False, 'text': "<p>In Lua:</p>\n\n<pre><code>function f()return 1+f()end f()\n</code></pre>\n\n<p>You've got to do something to the result of the recursive call, or else tail call optimization will allow it to loop forever. Weak for code golf, but nice to have!</p>\n\n<p>I guess that and the lengthy keywords mean Lua won't be winning the code golf anytime soon.</p>\n"}, {'answer_id': 63290, 'author': 'tomdemuyt', 'author_id': 7602, 'author_profile': 'https://Stackoverflow.com/users/7602', 'pm_score': 2, 'selected': False, 'text': '<p>batch program called call.cmd;</p>\n\n<p>call call.cmd</p>\n\n<pre><code>******  B A T C H   R E C U R S I O N  exceeds STACK limits ******\nRecursion Count=1240, Stack Usage=90 percent\n******       B A T C H   PROCESSING IS   A B O R T E D      ******\n</code></pre>\n'}, {'answer_id': 63353, 'author': 'davidnicol', 'author_id': 7420, 'author_profile': 'https://Stackoverflow.com/users/7420', 'pm_score': 0, 'selected': False, 'text': '<p><strong>Perl</strong> in 10 chars</p>\n\n<pre><code>sub x{&amp;x}x\n</code></pre>\n\n<p>Eventually uses up all available memory.</p>\n'}, {'answer_id': 63400, 'author': 'davidnicol', 'author_id': 7420, 'author_profile': 'https://Stackoverflow.com/users/7420', 'pm_score': 0, 'selected': False, 'text': '<p><strong>MS-DOS batch:</strong></p>\n\n<pre><code>copy CON so.bat\nso.bat\n^Z\nso.bat\n</code></pre>\n'}, {'answer_id': 63519, 'author': 'Misha', 'author_id': 7557, 'author_profile': 'https://Stackoverflow.com/users/7557', 'pm_score': 3, 'selected': False, 'text': '<p>Java</p>\n\n<p>Slightly shorter version of the Java solution.</p>\n\n<pre><code>class X{public static void main(String[]a){main(a);}}\n</code></pre>\n'}, {'answer_id': 63529, 'author': 'Kyle Cronin', 'author_id': 658, 'author_profile': 'https://Stackoverflow.com/users/658', 'pm_score': 2, 'selected': False, 'text': '<p>In Scheme, this will cause the interpreter to run out of memory:</p>\n\n<pre><code>(define (x)\n  ((x)))\n\n(x)\n</code></pre>\n'}, {'answer_id': 63534, 'author': 'Antti Kissaniemi', 'author_id': 2948, 'author_profile': 'https://Stackoverflow.com/users/2948', 'pm_score': 1, 'selected': False, 'text': "<p>Shell script solution in <strong>10 characters</strong> including newlines:</p>\n\n<p>Well, technically not stack overflow but logically so, if you consider spawning a new process as constructing a new stack frame.</p>\n\n<pre><code>#!sh\n./so\n</code></pre>\n\n<p>Result:</p>\n\n<pre><code>antti@blah:~$ ./so\n[disconnected]\n</code></pre>\n\n<p>Whoops. Note: <strong>don't try this at home</strong></p>\n"}, {'answer_id': 63613, 'author': 'Robert S.', 'author_id': 7565, 'author_profile': 'https://Stackoverflow.com/users/7565', 'pm_score': 2, 'selected': False, 'text': "<p>In Whitespace, I think:</p>\n\n<p>It probably won't show up. :/</p>\n"}, {'answer_id': 63812, 'author': 'bk1e', 'author_id': 8090, 'author_profile': 'https://Stackoverflow.com/users/8090', 'pm_score': 4, 'selected': False, 'text': '<p><strong>C</strong> - It\'s not the shortest, but it\'s recursion-free. It\'s also not portable: it crashes on Solaris, but some alloca() implementations might return an error here (or call malloc()). The call to printf() is necessary.</p>\n\n<pre><code>#include &lt;stdio.h&gt;\n#include &lt;alloca.h&gt;\n#include &lt;sys/resource.h&gt;\nint main(int argc, char *argv[]) {\n    struct rlimit rl = {0};\n    getrlimit(RLIMIT_STACK, &amp;rl);\n    (void) alloca(rl.rlim_cur);\n    printf("Goodbye, world\\n");\n    return 0;\n}\n</code></pre>\n'}, {'answer_id': 63848, 'author': 'Amy B', 'author_id': 8155, 'author_profile': 'https://Stackoverflow.com/users/8155', 'pm_score': 0, 'selected': False, 'text': '<p>C# with 27 non-whitespace characters - includes the call.</p>\n\n<pre><code>Action a = null;\na = () =&gt; a();\na();\n</code></pre>\n'}, {'answer_id': 63873, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<pre><code>xor esp, esp\nret\n</code></pre>\n'}, {'answer_id': 64017, 'author': 'x0n', 'author_id': 6920, 'author_profile': 'https://Stackoverflow.com/users/6920', 'pm_score': 1, 'selected': False, 'text': '<p><strong>PowerShell</strong></p>\n\n<blockquote>\n  <p>$f={&amp;$f};&amp;$f</p>\n</blockquote>\n\n<p>"The script failed due to call depth overflow.  The call depth reached 1001 and the maximum is 1000."</p>\n'}, {'answer_id': 64252, 'author': 'jrudolph', 'author_id': 7647, 'author_profile': 'https://Stackoverflow.com/users/7647', 'pm_score': 8, 'selected': False, 'text': '<p>Read this line, and do what it says <strong>twice</strong>.</p>\n'}, {'answer_id': 64290, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p><strong>bash:</strong> Only one process</p>\n\n<pre><code>\\#!/bin/bash\nof() { of; }\nof\n</code></pre>\n'}, {'answer_id': 64331, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Ruby, shorter than the other ones so far:</p>\n\n<pre><code>def a;a;end;a\n</code></pre>\n\n<p>(13 chars)</p>\n'}, {'answer_id': 64346, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Pretty much any shell:</p>\n\n<pre><code>sh $0\n</code></pre>\n\n<p>(5 characters, only works if run from file)</p>\n'}, {'answer_id': 64352, 'author': 'user8456', 'author_id': 8456, 'author_profile': 'https://Stackoverflow.com/users/8456', 'pm_score': 4, 'selected': False, 'text': '<p>try and put more than 4 patties on a single burger. stack overflow.</p>\n'}, {'answer_id': 64395, 'author': 'Chris Broadfoot', 'author_id': 3947, 'author_profile': 'https://Stackoverflow.com/users/3947', 'pm_score': 4, 'selected': False, 'text': '<p>Groovy:</p>\n\n<pre><code>main()\n</code></pre>\n\n<p>$ groovy stack.groovy:</p>\n\n<pre><code>Caught: java.lang.StackOverflowError\n    at stack.main(stack.groovy)\n    at stack.run(stack.groovy:1)\n ...\n</code></pre>\n'}, {'answer_id': 64425, 'author': 'Jonas Engström', 'author_id': 7634, 'author_profile': 'https://Stackoverflow.com/users/7634', 'pm_score': 0, 'selected': False, 'text': '<p>Five bytes in 16-bit asm which will cause a stack overflow.</p>\n\n<pre><code>push cs\npush $-1\nret\n</code></pre>\n'}, {'answer_id': 64573, 'author': 'botismarius', 'author_id': 4528, 'author_profile': 'https://Stackoverflow.com/users/4528', 'pm_score': 1, 'selected': False, 'text': '<p>In assembly language (x86 processors, 16 or 32 bit mode):</p>\n\n<pre><code>\ncall $\n</code></pre>\n\n<p>which will generate:</p>\n\n<ul>\n<li><p>in 32 bit mode: 0xe8;0xfb;0xff;0xff;0xff</p></li>\n<li><p>in 16 bit mode: 0xe8;0xfd;0xff</p></li>\n</ul>\n\n<p>in C/C++:</p>\n\n<pre><code>\nint main( ) {\n  return main( );\n}\n</code></pre>\n'}, {'answer_id': 64707, 'author': 'Dennis Munsie', 'author_id': 8728, 'author_profile': 'https://Stackoverflow.com/users/8728', 'pm_score': 5, 'selected': False, 'text': '<p>Z-80 assembler -- at memory location 0x0000:</p>\n\n<pre><code>rst 00\n</code></pre>\n\n<p>one byte -- 0xC7 -- endless loop of pushing the current PC to the stack and jumping to address 0x0000.</p>\n'}, {'answer_id': 64830, 'author': 'Travis Wilson', 'author_id': 8735, 'author_profile': 'https://Stackoverflow.com/users/8735', 'pm_score': 4, 'selected': False, 'text': "<p><strong>Javascript</strong></p>\n\n<p>To trim a few more characters, and to get ourselves kicked out of more software shops, let's go with:</p>\n\n<pre><code>eval(i='eval(i)');\n</code></pre>\n"}, {'answer_id': 65046, 'author': 'mattiast', 'author_id': 8272, 'author_profile': 'https://Stackoverflow.com/users/8272', 'pm_score': 2, 'selected': False, 'text': '<p>Haskell:</p>\n\n<pre><code>let x = x\nprint x\n</code></pre>\n'}, {'answer_id': 65224, 'author': 'Joshua Carmody', 'author_id': 8409, 'author_profile': 'https://Stackoverflow.com/users/8409', 'pm_score': 2, 'selected': False, 'text': '<p>Well, nobody\'s mentioned Coldfusion yet, so...</p>\n\n<pre><code>&lt;cfinclude template="#ListLast(CGI.SCRIPT_NAME, "/\\")#"&gt;\n</code></pre>\n\n<p>That oughta do it.</p>\n'}, {'answer_id': 65317, 'author': 'Kibbee', 'author_id': 1862, 'author_profile': 'https://Stackoverflow.com/users/1862', 'pm_score': 0, 'selected': False, 'text': '<p>VB.Net</p>\n\n<pre><code>Function StackOverflow() As Integer\n    Return StackOverflow()\nEnd Function\n</code></pre>\n'}, {'answer_id': 65628, 'author': 'Joseph Bui', 'author_id': 3275, 'author_profile': 'https://Stackoverflow.com/users/3275', 'pm_score': 1, 'selected': False, 'text': '<p>TCL:</p>\n\n<pre><code>proc a {} a\n</code></pre>\n\n<p>I don\'t have a tclsh interpreter that can do tail recursion, but this might fool such a thing:</p>\n\n<pre><code>proc a {} "a;a"\n</code></pre>\n'}, {'answer_id': 66095, 'author': 'Alex M', 'author_id': 9652, 'author_profile': 'https://Stackoverflow.com/users/9652', 'pm_score': 2, 'selected': False, 'text': '<p>Forth:</p>\n\n<pre><code>: a 1 recurse ; a\n</code></pre>\n\n<p>Inside the <code>gforth</code> interpreter:</p>\n\n<pre><code>: a 1 recurse ; a \n*the terminal*:1: Return stack overflow\n: a 1 recurse ; a\n                ^\nBacktrace:\n</code></pre>\n\n<p>On a Power Mac G4 at the Open Firmware prompt, this just hangs the machine. :)</p>\n'}, {'answer_id': 66370, 'author': 'Kemal', 'author_id': 7506, 'author_profile': 'https://Stackoverflow.com/users/7506', 'pm_score': 5, 'selected': False, 'text': '<p>Another PHP Example:</p>\n\n<pre><code>&lt;?\nrequire(__FILE__);\n</code></pre>\n'}, {'answer_id': 66392, 'author': 'PersistenceOfVision', 'author_id': 6721, 'author_profile': 'https://Stackoverflow.com/users/6721', 'pm_score': 0, 'selected': False, 'text': '<p>For Fun I had to look up the Motorolla HC11 Assembly:</p>\n\n<pre><code>              org           $100\nLoop    nop\n          jsr            Loop\n</code></pre>\n'}, {'answer_id': 66470, 'author': 'WaldWolf', 'author_id': 9764, 'author_profile': 'https://Stackoverflow.com/users/9764', 'pm_score': -1, 'selected': False, 'text': '<p><strong>Prolog</strong></p>\n\n<p>p:-p.</p>\n\n<p>= 5 characters</p>\n\n<p>then start it and query p</p>\n\n<p>i think that is quite small and runs out of stack in prolog.</p>\n\n<p>a query of just a variable in swi prolog produces:</p>\n\n<p>?- X.\n% ... 1,000,000 ............ 10,000,000 years later\n% \n%       >> 42 &lt;&lt; (last release gives the question)</p>\n\n<p>and here is another bash fork bomb:\n:(){ :|:&amp; };:</p>\n'}, {'answer_id': 66483, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>as a local variable in a C function:</p>\n\n<pre><code>int x[100000000000];\n</code></pre>\n'}, {'answer_id': 66616, 'author': 'Thevs', 'author_id': 8559, 'author_profile': 'https://Stackoverflow.com/users/8559', 'pm_score': 0, 'selected': False, 'text': '<p>Not very short, but effective! (JavaScript)</p>\n\n<pre><code>setTimeout(1, function() {while(1) a=1;});\n</code></pre>\n'}, {'answer_id': 66663, 'author': 'Jay Bazuzi', 'author_id': 5314, 'author_profile': 'https://Stackoverflow.com/users/5314', 'pm_score': 2, 'selected': False, 'text': '<p><strong>C#</strong> </p>\n\n<pre><code>class _{static void Main(){Main();}}\n</code></pre>\n\n<p>Note that mine is a compilable program, not just a single function.  I also removed excess whitespace.</p>\n\n<p>For flair, I made the class name as small as I could.</p>\n'}, {'answer_id': 66744, 'author': 'Patrick', 'author_id': 429, 'author_profile': 'https://Stackoverflow.com/users/429', 'pm_score': 9, 'selected': True, 'text': '<p>All these answers and no Befunge? I\'d wager a fair amount it\'s shortest solution of them all:</p>\n\n<pre><code>1\n</code></pre>\n\n<p>Not kidding. Try it yourself: <a href="http://www.quirkster.com/iano/js/befunge.html" rel="nofollow noreferrer">http://www.quirkster.com/iano/js/befunge.html</a></p>\n\n<p>EDIT: 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. </p>\n\n<p>Using the interpreter provided, you will eventually--and I mean <i>eventually</i>--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.</p>\n'}, {'answer_id': 67634, 'author': 'clahey', 'author_id': 8453, 'author_profile': 'https://Stackoverflow.com/users/8453', 'pm_score': 2, 'selected': False, 'text': "<p>Unless there's a language where the empty program causes a stack overflow, the following should be the shortest possible.</p>\n\n<p>Befunge:</p>\n\n<pre><code>:\n</code></pre>\n\n<p>Duplicates the top stack value over and over again.</p>\n\n<p>edit:\n Patrick's is better.  Filling the stack with 1s is better than filling the stack with 0s, since the interpreter could optimize pushing 0s onto an empty stack as a no-op.</p>\n"}, {'answer_id': 67749, 'author': 'Despatcher', 'author_id': 10240, 'author_profile': 'https://Stackoverflow.com/users/10240', 'pm_score': 0, 'selected': False, 'text': "<p>I think it's cheating I've never played before ;) but here goes</p>\n\n<p>8086 assembler:</p>\n\n<p>org Int3VectorAdrress ;is that cheating? </p>\n\n<p>int 3</p>\n\n<p>1 byte - or 5 characters that generate code, what say you? </p>\n"}, {'answer_id': 68055, 'author': 'user4010', 'author_id': 4010, 'author_profile': 'https://Stackoverflow.com/users/4010', 'pm_score': 2, 'selected': False, 'text': '<p>If you consider a call frame to be a process, and the stack to be your Unix machine, you could consider a fork bomb to be a <em>parallel</em> program to create a stack overflow condition.  Try this 13-character bash number.  No saving to a file is necessary.</p>\n\n<pre><code>:(){ :|:&amp; };:\n</code></pre>\n'}, {'answer_id': 68229, 'author': 'RFelix', 'author_id': 10582, 'author_profile': 'https://Stackoverflow.com/users/10582', 'pm_score': 0, 'selected': False, 'text': '<p>Ruby, albeit not that short:</p>\n\n<pre><code>class Overflow\n    def initialize\n        Overflow.new\n    end\nend\n\nOverflow.new\n</code></pre>\n'}, {'answer_id': 68442, 'author': 'Alex M', 'author_id': 9652, 'author_profile': 'https://Stackoverflow.com/users/9652', 'pm_score': 5, 'selected': False, 'text': '<p>TeX:</p>\n\n<pre><code>\\def~{~.}~\n</code></pre>\n\n<p>Results in:</p>\n\n<pre>! TeX capacity exceeded, sorry [input stack size=5000].\n~->~\n    .\n~->~\n    .\n~->~\n    .\n~->~\n    .\n~->~\n    .\n~->~\n    .\n...\n&lt;*> \\def~{~.}~</pre>\n\n<p>LaTeX:</p>\n\n<pre><code>\\end\\end\n</code></pre>\n\n<p>Results in:</p>\n\n<pre>! TeX capacity exceeded, sorry [input stack size=5000].\n\\end #1->\\csname end#1\n                      \\endcsname \\@checkend {#1}\\expandafter \\endgroup \\if@e...\n&lt;*> \\end\\end</pre>\n'}, {'answer_id': 68521, 'author': 'Daniel Spiewak', 'author_id': 9815, 'author_profile': 'https://Stackoverflow.com/users/9815', 'pm_score': -1, 'selected': False, 'text': '<p>I think this will work in Java (untried):</p>\n\n<pre><code>enum A{B.values()}\nenum B{A.values()}\n</code></pre>\n\n<p>Should overflow in static initialization before it even gets the chance to fail due to a lack of main(String[]).</p>\n'}, {'answer_id': 68586, 'author': 'user10178', 'author_id': 10178, 'author_profile': 'https://Stackoverflow.com/users/10178', 'pm_score': 1, 'selected': False, 'text': "<p>won't be the shortest but I had to try something... C#</p>\n\n<p>string[] f = new string[0]; Main(f);</p>\n\n<p>bit shorter</p>\n\n<pre><code>static void Main(){Main();}\n</code></pre>\n"}, {'answer_id': 68960, 'author': 'Ryan Fox', 'author_id': 55, 'author_profile': 'https://Stackoverflow.com/users/55', 'pm_score': 4, 'selected': False, 'text': "<pre><code>Person JeffAtwood;\nPerson JoelSpolsky;\nJeffAtwood.TalkTo(JoelSpolsky);\n</code></pre>\n\n<p>Here's hoping for no tail recursion!</p>\n"}, {'answer_id': 69003, 'author': 'Jude Allred', 'author_id': 1388, 'author_profile': 'https://Stackoverflow.com/users/1388', 'pm_score': 4, 'selected': False, 'text': '<p>Using a Window\'s batch file named "s.bat":</p>\n\n<pre><code>call s\n</code></pre>\n'}, {'answer_id': 69369, 'author': 'user11039', 'author_id': 11039, 'author_profile': 'https://Stackoverflow.com/users/11039', 'pm_score': 0, 'selected': False, 'text': '<p>In <strong>C#</strong>, this would create a stackoverflow...</p>\n\n<pre><code>static void Main()\n{\n    Main();\n}\n</code></pre>\n'}, {'answer_id': 69577, 'author': 'mike511', 'author_id': 9593, 'author_profile': 'https://Stackoverflow.com/users/9593', 'pm_score': 0, 'selected': False, 'text': '<p>why not</p>\n\n<pre><code>mov sp,0\n</code></pre>\n\n<p>(stack grows down)</p>\n'}, {'answer_id': 69626, 'author': 'Mark Nold', 'author_id': 4134, 'author_profile': 'https://Stackoverflow.com/users/4134', 'pm_score': 0, 'selected': False, 'text': '<p>In a <strong>PostScript</strong> file called so.ps will cause execstackoverflow</p>\n\n<pre><code>%!PS\n/increase {1 add} def\n1 increase\n(so.ps) run\n</code></pre>\n'}, {'answer_id': 70176, 'author': 'Wouter Coekaerts', 'author_id': 3432, 'author_profile': 'https://Stackoverflow.com/users/3432', 'pm_score': 2, 'selected': False, 'text': '<p>In Irssi (terminal based IRC client, not "really" a programming language), $L means the current command line. So you can cause a stack overflow ("hit maximum recursion limit") with:</p>\n\n<pre><code>/eval $L\n</code></pre>\n'}, {'answer_id': 70398, 'author': 'Konrad Rudolph', 'author_id': 1968, 'author_profile': 'https://Stackoverflow.com/users/1968', 'pm_score': 6, 'selected': False, 'text': '<p>Every task needs the right tool. Meet the <a href="http://page.mi.fu-berlin.de/krudolph/stuff/so/" rel="nofollow noreferrer">SO Overflow</a> language, optimized to produce stack overflows:</p>\n\n<pre><code>so\n</code></pre>\n'}, {'answer_id': 70950, 'author': 'RFelix', 'author_id': 10582, 'author_profile': 'https://Stackoverflow.com/users/10582', 'pm_score': 1, 'selected': False, 'text': "<p>Here's another Ruby answer, this one uses lambdas:</p>\n\n<pre><code>(a=lambda{a.call}).call\n</code></pre>\n"}, {'answer_id': 71833, 'author': 'C. K. Young', 'author_id': 13, 'author_profile': 'https://Stackoverflow.com/users/13', 'pm_score': 3, 'selected': False, 'text': '<p>I\'m selecting the “best answer” after this post. But first, I\'d like to acknowledge some very original contributions:</p>\n\n<ol>\n<li>aku\'s ones. Each one explores a new and original way of causing stack overflow. The idea of doing f(x) ⇒ f(f(x)) is one I\'ll explore in my next entry, below. :-)</li>\n<li>Cody\'s one that gave the Nemerle <em>compiler</em> a stack overflow.</li>\n<li>And (a bit grudgingly), GateKiller\'s one about throwing a stack overflow exception. :-P</li>\n</ol>\n\n<p>Much as I love the above, the challenge is about doing code golf, and to be fair to respondents, I have to award “best answer” to the shortest code, which is the Befunge entry; I don\'t believe anybody will be able to beat that (although Konrad has certainly tried), so congrats Patrick!</p>\n\n<p>Seeing the large number of stack-overflow-by-recursion solutions, I\'m surprised that nobody has (as of current writing) brought up the Y combinator (see Dick Gabriel\'s essay, <a href="http://www.dreamsongs.com/Files/WhyOfY.pdf" rel="nofollow noreferrer">The Why of Y</a>, for a primer). I have a recursive solution that uses the Y combinator, as well as aku\'s f(f(x)) approach. :-)</p>\n\n<pre><code>((Y (lambda (f) (lambda (x) (f (f x))))) #f)\n</code></pre>\n'}, {'answer_id': 71964, 'author': 'Leo Lännenmäki', 'author_id': 2451, 'author_profile': 'https://Stackoverflow.com/users/2451', 'pm_score': 1, 'selected': False, 'text': '<p>Another one in <strong>JavaScript</strong>:</p>\n\n<pre><code>(function() { arguments.callee() })()\n</code></pre>\n'}, {'answer_id': 72993, 'author': 'Javier', 'author_id': 12449, 'author_profile': 'https://Stackoverflow.com/users/12449', 'pm_score': 1, 'selected': False, 'text': '<p>Vb6</p>\n\n<pre><code>\nPublic Property Let x(ByVal y As Long)\n  x = y\nEnd Property\n\nPrivate Sub Class_Initialize()\n  x = 0\nEnd Sub\n</code></pre>\n'}, {'answer_id': 75948, 'author': 'squadette', 'author_id': 7754, 'author_profile': 'https://Stackoverflow.com/users/7754', 'pm_score': 1, 'selected': False, 'text': '<p>Short solution in K&amp;R C, could be compiled:</p>\n\n<pre><code>main(){main()}\n</code></pre>\n\n<p>14 bytes</p>\n'}, {'answer_id': 75991, 'author': 'Adam Rosenfield', 'author_id': 9530, 'author_profile': 'https://Stackoverflow.com/users/9530', 'pm_score': 3, 'selected': False, 'text': "<p>Here's another interesting one from Scheme:</p>\n\n<pre>((lambda (x) (x x)) (lambda (x) (x x)))</pre>\n"}, {'answer_id': 76923, 'author': 'Ramin', 'author_id': 8919, 'author_profile': 'https://Stackoverflow.com/users/8919', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.google.com/search?q=google.com" rel="nofollow noreferrer">http://www.google.com/search?q=google.com</a></p>\n'}, {'answer_id': 78084, 'author': 'defmeta', 'author_id': 10875, 'author_profile': 'https://Stackoverflow.com/users/10875', 'pm_score': 0, 'selected': False, 'text': "<p>Actionscript 3: All done with arrays...</p>\n\n<pre><code>var i=[];\ni[i.push(i)]=i;\ntrace(i);\n</code></pre>\n\n<p>Maybe not the smallest but I think it's cute. Especially the push method returning the new array length!</p>\n"}, {'answer_id': 78911, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>In response to the Y combinator comment, i might as well through in the Y-combinator in the SKI calculus:</p>\n\n<pre><code>S (K (S I I)) (S (S (K S) K) (K (S I I)))\n</code></pre>\n\n<p>There aren\'t any SKI interpreters that i know of but i once wrote a graphical one in about an hour in actionscript. I would be willing to post if there is interest (though i never got the layout working very efficiently)</p>\n\n<p>read all about it here:\n<a href="http://en.wikipedia.org/wiki/SKI_combinator_calculus" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/SKI_combinator_calculus</a></p>\n'}, {'answer_id': 79016, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>In x86 assembly, place a divide by 0 instruction at the location in memory of the interrupt handler for divide by 0!</p>\n'}, {'answer_id': 80350, 'author': 'matyr', 'author_id': 15066, 'author_profile': 'https://Stackoverflow.com/users/15066', 'pm_score': 2, 'selected': False, 'text': '<p>Groovy (5B):</p>\n\n<pre><code>run()\n</code></pre>\n'}, {'answer_id': 90506, 'author': 'dsm', 'author_id': 7780, 'author_profile': 'https://Stackoverflow.com/users/7780', 'pm_score': 1, 'selected': False, 'text': '<p>in perl:</p>\n\n<pre><code>`$0`\n</code></pre>\n\n<p>As a matter of fact, this will work with any shell that supports the backquote-command syntax and stores its own name in <code>$0</code></p>\n'}, {'answer_id': 90986, 'author': 'Aardappel', 'author_id': 17419, 'author_profile': 'https://Stackoverflow.com/users/17419', 'pm_score': 1, 'selected': False, 'text': '<p>False:</p>\n\n<p>[1][1]#</p>\n\n<p>(False is a stack language: # is a while loop that takes 2 closures, a conditional and a body. The body is the one that causes the overflow).</p>\n'}, {'answer_id': 570789, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>CMD overflow in one line</p>\n\n<pre><code>echo @call b.cmd &gt; b.cmd &amp; b\n</code></pre>\n'}, {'answer_id': 583659, 'author': 'Kaarel', 'author_id': 12547, 'author_profile': 'https://Stackoverflow.com/users/12547', 'pm_score': 0, 'selected': False, 'text': '<p><strong>Prolog</strong></p>\n\n<p>This program crashes both SWI-Prolog and Sicstus Prolog when consulted.</p>\n\n<pre><code>p :- p, q.\n:- p.\n</code></pre>\n'}, {'answer_id': 597337, 'author': 'Oscar Cabrero', 'author_id': 14440, 'author_profile': 'https://Stackoverflow.com/users/14440', 'pm_score': -1, 'selected': False, 'text': '<pre><code>Redmond.Microsoft.Core.Windows.Start()\n</code></pre>\n'}, {'answer_id': 597372, 'author': 'Adam Davis', 'author_id': 2915, 'author_profile': 'https://Stackoverflow.com/users/2915', 'pm_score': 7, 'selected': False, 'text': '<h2>PIC18</h2>\n\n<p>The <a href="https://stackoverflow.com/questions/62188/stack-overflow-code-golf/62209#62209">PIC18 answer given by TK</a> results in the following instructions (binary):</p>\n\n<pre><code>overflow\n   PUSH\n   0000 0000 0000 0101\n   CALL overflow\n   1110 1100 0000 0000\n   0000 0000 0000 0000\n</code></pre>\n\n<p>However, CALL alone will perform a stack overflow:</p>\n\n<pre><code>CALL $\n1110 1100 0000 0000\n0000 0000 0000 0000\n</code></pre>\n\n<h2>Smaller, faster PIC18</h2>\n\n<p>But RCALL (relative call) is smaller still (not global memory, so no need for the extra 2 bytes):</p>\n\n<pre><code>RCALL $\n1101 1000 0000 0000\n</code></pre>\n\n<p>So the smallest on the PIC18 is a single instruction, 16 bits (two bytes).  This would take 2 instruction cycles per loop.  At 4 clock cycles per instruction cycle you\'ve got 8 clock cycles.  The PIC18 has a 31 level stack, so after the 32nd loop it will overflow the stack, in 256 clock cycles.  At 64MHz, you would <strong>overflow the stack in 4 micro seconds and 2 bytes</strong>.</p>\n\n<h2>PIC16F5x (even smaller and faster)</h2>\n\n<p>However, the PIC16F5x series uses 12 bit instructions:</p>\n\n<pre><code>CALL $\n1001 0000 0000\n</code></pre>\n\n<p>Again, two instruction cycles per loop, 4 clocks per instruction so 8 clock cycles per loop.</p>\n\n<p>However, the PIC16F5x has a two level stack, so on the third loop it would overflow, in 24 instructions.  At 20MHz, it would <strong>overflow in 1.2 micro seconds and 1.5 bytes</strong>.</p>\n\n<h2>Intel 4004</h2>\n\n<p>The <a href="http://download.intel.com/museum/archives/pdf/4004_datasheet.pdf" rel="nofollow noreferrer">Intel 4004</a> has an 8 bit call subroutine instruction:</p>\n\n<pre><code>CALL $\n0101 0000\n</code></pre>\n\n<p>For the curious that corresponds to an ascii \'P\'.  With a 3 level stack that takes 24 clock cycles for a total of <strong>32.4 micro seconds and one byte</strong>.  (Unless you overclock your 4004 - come on, you know you want to.)</p>\n\n<p>Which is as small as the befunge answer, but much, much faster than the befunge code running in current interpreters.</p>\n'}, {'answer_id': 597461, 'author': 'Svante', 'author_id': 31615, 'author_profile': 'https://Stackoverflow.com/users/31615', 'pm_score': 0, 'selected': False, 'text': '<p>Tail call optimization can be sabotaged by not tail calling. In Common Lisp:</p>\n\n<pre>(defun f () (1+ (f)))</pre>\n'}, {'answer_id': 605938, 'author': 'Jonas Kölker', 'author_id': 58668, 'author_profile': 'https://Stackoverflow.com/users/58668', 'pm_score': 1, 'selected': False, 'text': '<p>In Haskell</p>\n\n<pre><code>fix (1+)\n</code></pre>\n\n<p>This tries to find the fix point of the (1+) function (<code>λ n → n + 1</code>) .  The implementation of fix is</p>\n\n<pre><code>fix f = (let x = f(x) in x)\n</code></pre>\n\n<p>So</p>\n\n<pre><code>fix (1+)\n</code></pre>\n\n<p>becomes</p>\n\n<pre><code>(1+) ((1+) ((1+) ...))\n</code></pre>\n\n<p>Note that</p>\n\n<pre><code>fix (+1)\n</code></pre>\n\n<p>just loops.</p>\n'}, {'answer_id': 779109, 'author': 'BCS', 'author_id': 1343, 'author_profile': 'https://Stackoverflow.com/users/1343', 'pm_score': 0, 'selected': False, 'text': '<p>Meta problem in D:</p>\n\n<pre><code>class C(int i) { C!(i+1) c; }\nC!(1) c;\n</code></pre>\n\n<p>compile time stack overflow</p>\n'}, {'answer_id': 848505, 'author': 'Tolgahan Albayrak', 'author_id': 104468, 'author_profile': 'https://Stackoverflow.com/users/104468', 'pm_score': 0, 'selected': False, 'text': '<pre><code>_asm t: call t;\n</code></pre>\n'}, {'answer_id': 973947, 'author': 'RCIX', 'author_id': 117069, 'author_profile': 'https://Stackoverflow.com/users/117069', 'pm_score': 1, 'selected': False, 'text': '<p><strong>A better lua solution:</strong></p>\n\n<pre><code>function c()c()end;\n</code></pre>\n\n<p>Stick this into SciTE or an interactive command prompt and then call it. Boom!</p>\n'}, {'answer_id': 1028904, 'author': 'Greg', 'author_id': 12601, 'author_profile': 'https://Stackoverflow.com/users/12601', 'pm_score': 4, 'selected': False, 'text': '<p>Please tell me what the acronym "<a href="http://en.wikipedia.org/wiki/GNU" rel="nofollow noreferrer">GNU</a>" stands for.</p>\n'}, {'answer_id': 1735693, 'author': 'Graphics Noob', 'author_id': 127669, 'author_profile': 'https://Stackoverflow.com/users/127669', 'pm_score': 0, 'selected': False, 'text': "<p>OCaml</p>\n\n<pre><code>let rec f l = f l@l;;\n</code></pre>\n\n<p>This one is a little different. There's only one stack frame on the stack (since it's tail recursive), but it's input keeps growing until it overflows the stack. Just call <code>f</code> with a non empty list like so (at the interpreter prompt):</p>\n\n<pre><code># f [0];;\nStack overflow during evaluation (looping recursion?).\n</code></pre>\n"}, {'answer_id': 1738894, 'author': 'Graphics Noob', 'author_id': 127669, 'author_profile': 'https://Stackoverflow.com/users/127669', 'pm_score': 0, 'selected': False, 'text': "<p>Even though it doesn't really have a stack...</p>\n\n<p><strong>brainf*ck 5 char</strong></p>\n\n<pre><code>+[&gt;+]\n</code></pre>\n"}, {'answer_id': 1985750, 'author': 'Tim Ring', 'author_id': 3685, 'author_profile': 'https://Stackoverflow.com/users/3685', 'pm_score': 0, 'selected': False, 'text': '<p>Z80 assembly language...</p>\n\n<pre><code>.org 1000\nloop: call loop\n</code></pre>\n\n<p>this generates 3 bytes of code at location 1000....</p>\n\n<p>1000 CD 00 10</p>\n'}, {'answer_id': 2101846, 'author': 'danielschemmel', 'author_id': 65678, 'author_profile': 'https://Stackoverflow.com/users/65678', 'pm_score': 2, 'selected': False, 'text': '<p>C#</p>\n\n<pre><code>class Program\n{\n    class StackOverflowExceptionOverflow : System.Exception\n    {\n        public StackOverflowExceptionOverflow()\n        {\n            throw new StackOverflowExceptionOverflow();\n        }\n    }\n\n    static void Main(string[] args)\n    {\n        throw new StackOverflowExceptionOverflow();\n    }\n}\n</code></pre>\n\n<p>I realize this is not the shortest (and even code golfed it would not come close to be anywhere near short), but I simply could not resist throwing an exception that while being thrown throws a stackoverflowexception, before it is able to terminate the runtime itself ^^</p>\n'}, {'answer_id': 2173039, 'author': 'finnw', 'author_id': 12048, 'author_profile': 'https://Stackoverflow.com/users/12048', 'pm_score': 0, 'selected': False, 'text': '<p>ruby (again):</p>\n\n<pre><code>def a(x);x.gsub(/./){a$0};end;a"x"\n</code></pre>\n\n<p>There are plenty of ruby solutions already but I thought I\'d throw in a regexp for good measure.</p>\n'}, {'answer_id': 2216158, 'author': 'KirarinSnow', 'author_id': 174376, 'author_profile': 'https://Stackoverflow.com/users/174376', 'pm_score': 2, 'selected': False, 'text': "<h1>PostScript, 7 characters</h1>\n\n<pre><code>{/}loop\n</code></pre>\n\n<p>When run in GhostScript, throws this exception:</p>\n\n<pre><code>GS&gt;{/}loop\nError: /stackoverflow in --execute--\nOperand stack:\n   --nostringval--\nExecution stack:\n   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   %loop_continue   1753   2   3   %oparray_pop   --nostringval--   --nostringval--   false   1   %stopped_push   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   %loop_continue\nDictionary stack:\n   --dict:1150/1684(ro)(G)--   --dict:0/20(G)--   --dict:70/200(L)--\nCurrent allocation mode is local\nLast OS error: 11\nCurrent file position is 8\n</code></pre>\n\n<p>Here's the recursive version without using variables (51 chars):</p>\n\n<pre><code>[{/[aload 8 1 roll]cvx exec}aload 8 1 roll]cvx exec\n</code></pre>\n"}, {'answer_id': 2343769, 'author': 'Carlos Gutiérrez', 'author_id': 237761, 'author_profile': 'https://Stackoverflow.com/users/237761', 'pm_score': 0, 'selected': False, 'text': '<p>Another Windows Batch file:</p>\n\n<pre><code>:a\n@call :a\n</code></pre>\n'}, {'answer_id': 2344985, 'author': 'N 1.1', 'author_id': 280730, 'author_profile': 'https://Stackoverflow.com/users/280730', 'pm_score': 0, 'selected': False, 'text': '<pre><code>main(){\n   main();\n}</code></pre>\n\n<p>Plain and nice C. Feels quite Intuitive to me.</p>\n'}, {'answer_id': 2348396, 'author': 'Brent Bradburn', 'author_id': 86967, 'author_profile': 'https://Stackoverflow.com/users/86967', 'pm_score': 1, 'selected': False, 'text': '<p>GNU make:</p>\n\n<p>Create a file called "Makefile" with the following contents:</p>\n\n<pre><code>a:\n    make\n</code></pre>\n\n<p>Then run make:</p>\n\n<pre><code>$ make\n</code></pre>\n\n<p>Note that a tab character must be used to offset the word "make".  This file is 9 characters, including the 2 end-of-line characters and the 1 tab character.</p>\n\n<p>I suppose you could do a similar thing with bash, but it\'s probably too easy to be interesting:</p>\n\n<p>Create a filename "b" and mark it as executable (chmod +x b):</p>\n\n<pre><code>b ## ties the winning entry with only one character (does not require end-of-line)\n</code></pre>\n\n<p>Now execute the file with</p>\n\n<pre><code>$ ( PATH=$PATH:. ; b )\n</code></pre>\n\n<p>It\'s hard to say whether this approach technically results in stack overflow, but it does build a stack which will grow until the machine runs out of resources.  The cool thing about doing it with GNU make is that you can watch it output status information as it builds and destroys the stack (assuming you hit ^C at some point before the crash occurs).</p>\n'}, {'answer_id': 2348499, 'author': 'Draemon', 'author_id': 26334, 'author_profile': 'https://Stackoverflow.com/users/26334', 'pm_score': 2, 'selected': False, 'text': '<p>Java:</p>\n\n<pre><code>class X{static{new X();}{new X();}}\n</code></pre>\n\n<p>Actually causes a stack overflow initializing the X class. Before main() is called, the JVM must load the class, and when it does so it triggers any anonymous static code blocks:</p>\n\n<pre><code>static {\n  new X();\n}\n</code></pre>\n\n<p>Which as you can see, instantiates X using the default constructor. The JVM will call anonymous code blocks even before the constructor:</p>\n\n<pre><code>{\n  new X();\n}\n</code></pre>\n\n<p>Which is the recursive part.</p>\n'}, {'answer_id': 2396631, 'author': "F'x", 'author_id': 143495, 'author_profile': 'https://Stackoverflow.com/users/143495', 'pm_score': 0, 'selected': False, 'text': '<h2>Fortran, 13 and 20 chars</h2>\n\n<pre><code>real n(0)\nn(1)=0\nend\n</code></pre>\n\n<p>or</p>\n\n<pre><code>call main\nend\n</code></pre>\n\n<p>The second case is compiler-dependent; for GNU Fortran, it will need to be compiled with <code>-fno-underscoring</code>.</p>\n\n<p>(Both counts include required newlines)</p>\n'}, {'answer_id': 2679742, 'author': 'Juliet', 'author_id': 40516, 'author_profile': 'https://Stackoverflow.com/users/40516', 'pm_score': 6, 'selected': False, 'text': '<p>Hoot overflow!</p>\n\n<pre><code>//              v___v\nlet rec f o = f(o);(o)\n//             [\'---\']\n//             -"---"-\n</code></pre>\n'}, {'answer_id': 2904167, 'author': 'jkramer', 'author_id': 12523, 'author_profile': 'https://Stackoverflow.com/users/12523', 'pm_score': 0, 'selected': False, 'text': '<p>Haskell:</p>\n\n<pre><code>main = print $ x 1 where x y = x y + 1\n</code></pre>\n'}, {'answer_id': 3029226, 'author': 'wash', 'author_id': 336878, 'author_profile': 'https://Stackoverflow.com/users/336878', 'pm_score': 0, 'selected': False, 'text': '<p>Dyalog APL</p>\n\n<pre><code>fib←{\n    ⍵∊0 1:⍵\n    +/∇¨⍵-1 2\n}\n</code></pre>\n'}, {'answer_id': 3029262, 'author': 'Daniel Băluţă', 'author_id': 328594, 'author_profile': 'https://Stackoverflow.com/users/328594', 'pm_score': 0, 'selected': False, 'text': '<pre><code>int main(void) { return main(); }\n</code></pre>\n'}, {'answer_id': 3171602, 'author': 'Cyclone', 'author_id': 113419, 'author_profile': 'https://Stackoverflow.com/users/113419', 'pm_score': 1, 'selected': False, 'text': '<p><a href="http://en.wikipedia.org/wiki/Php" rel="nofollow noreferrer">PHP</a> is a recursive acronym</p>\n'}, {'answer_id': 3230616, 'author': 'Artur Gaspar', 'author_id': 286655, 'author_profile': 'https://Stackoverflow.com/users/286655', 'pm_score': 0, 'selected': False, 'text': '<p>Python:</p>\n\n<pre><code>import sys  \nsys.setrecursionlimit(sys.maxint)  \ndef so():  \n    so()  \nso()\n</code></pre>\n'}, {'answer_id': 3272869, 'author': 'Ming-Tang', 'author_id': 303939, 'author_profile': 'https://Stackoverflow.com/users/303939', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Java: 35 characters</strong></p>\n\n<p>I think it\'s too late, but I will still post my idea:</p>\n\n<pre><code>class A{{new A();}static{new A();}}\n</code></pre>\n\n<p>Using the static initializer and instance initializer features.</p>\n\n<p>Here is the output on my computer (notice it showed two error messages):</p>\n\n<pre><code>Exception in thread "main" java.lang.StackOverflowError\n    at A.&lt;init&gt;(A.java:1)\n        ......\n    at A.&lt;init&gt;(A.java:1)\nCould not find the main class: A. Program will exit.\n</code></pre>\n\n<p>See also: <a href="http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/java/javaOO/initial.html" rel="nofollow noreferrer">http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/java/javaOO/initial.html</a></p>\n'}, {'answer_id': 3343950, 'author': 'st0le', 'author_id': 216517, 'author_profile': 'https://Stackoverflow.com/users/216517', 'pm_score': 0, 'selected': False, 'text': '<h2>JavaScript (17 Bytes)</h2>\n\n<pre><code>eval(t="eval(t)")\n</code></pre>\n\n<h2>VB Script (25 Bytes)</h2>\n\n<pre><code>t="Execute(t)":Execute(t)\n</code></pre>\n'}, {'answer_id': 3605353, 'author': 'Ming-Tang', 'author_id': 303939, 'author_profile': 'https://Stackoverflow.com/users/303939', 'pm_score': 2, 'selected': False, 'text': '<h1>C++ Compiler Error Message</h1>\n<pre><code>template&lt;int n&gt;struct f{f&lt;n+1&gt;a;};f&lt;0&gt;::a;\n</code></pre>\n<p>output:</p>\n<pre><code>$ g++ test.cpp;\ntest.cpp:1: error: template instantiation depth exceeds maximum of 500 (use -ftemplate-depth-NN to increase the maximum) instantiating ‘struct f&lt;500&gt;’\ntest.cpp:1:   instantiated from ‘f&lt;499&gt;’\ntest.cpp:1:   instantiated from ‘f&lt;498&gt;’\n......\n</code></pre>\n<p>Even if the compiler went through the template, there will be the next error: missing <code>main</code>.</p>\n'}]
['https://Stackoverflow.com/questions/62188', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13/']