78
\$\begingroup\$

Write a program that throws a StackOverflow Error or the equivalent in the language used. For example, in java, the program should throw java.lang.StackOverflowError.

You are not allowed to define a function that calls itself or a new class(except the one containing main in java). It should use the classes of the selected programming language.

And it should not throw the error explicitly.

\$\endgroup\$
9
  • 4
    \$\begingroup\$ I don't understand "use the classes of the selected programming language" \$\endgroup\$ Commented Jan 4, 2013 at 15:07
  • 3
    \$\begingroup\$ Is it ok to define a function that calls inner function like this def s{def t=s;t} ? \$\endgroup\$ Commented Jan 4, 2013 at 15:10
  • 13
    \$\begingroup\$ In most languages, classes are only a special kind of data structure, not the center of the universe. Many don't even have such a thing. \$\endgroup\$ Commented Jan 4, 2013 at 21:42
  • 1
    \$\begingroup\$ The funny thing here is that languages that require tail recursion elimination (and implementations that support it when the languages does not require it)---which are in a very real sense better---are at a disadvantage on this. TwiNight's answer links to the version of this that exists on Stack Overflow from the early days. \$\endgroup\$ Commented Jan 4, 2013 at 22:13
  • 1
    \$\begingroup\$ From the java doc: Thrown when a stack overflow occurs because an application recurses too deeply. docs.oracle.com/javase/6/docs/api/java/lang/… \$\endgroup\$
    – jsedano
    Commented Apr 9, 2013 at 16:24

68 Answers 68

90
\$\begingroup\$

Befunge, 1

I don't know Befunge, but...

1

from Stack overflow code golf

\$\endgroup\$
4
  • 21
    \$\begingroup\$ Explanation: 1 is a numeric literal that gets pushed to the stack when encountered. In Befunge, control flow wraps around until it encounters an @ to end the program. \$\endgroup\$
    – histocrat
    Commented Jan 4, 2013 at 17:30
  • 6
    \$\begingroup\$ I didn't know there was this question on StackOverflow. I searched only on this site before posting. \$\endgroup\$
    – True Soft
    Commented Jan 5, 2013 at 8:26
  • 32
    \$\begingroup\$ I'm mildly flattered to see my answer here. \$\endgroup\$
    – Patrick
    Commented Apr 9, 2013 at 1:50
  • 4
    \$\begingroup\$ This works in ><> too. \$\endgroup\$
    – Cruncher
    Commented Nov 6, 2013 at 15:09
51
\$\begingroup\$

Python (2.7.3), 35 characters

import sys
sys.setrecursionlimit(1)

This operation itself succeeds, but both script and interactive will immediately throw RuntimeError: 'maximum recursion depth exceeded' afterward as a consequence.

Inspired by elssar's answer.

\$\endgroup\$
2
  • \$\begingroup\$ I thought about putting that up as my solution instead, but wasn't sure if the error could be considered a stack overflow. Though, essentially, that is what it is, right? \$\endgroup\$
    – elssar
    Commented Jan 5, 2013 at 8:25
  • 2
    \$\begingroup\$ @elssar: I guess there are two ways to overflow the stack: make the used part of the stack larger, or make the unused part of the stack smaller. If you imagine a bucket filling with water, you can overflow it by adding more water, but you can also overflow it by shrinking the bucket. \$\endgroup\$
    – user62131
    Commented Jun 2, 2017 at 14:51
21
\$\begingroup\$

Coq

Compute 70000.

70000 is just syntactic sugar for S (S ( ... (S O) ...)) with 70000 S's. I think it's the type checker that causes the stack overflow.

Here's a warning that is printed before the command is executed:

Warning: Stack overflow or segmentation fault happens when working with large
numbers in nat (observed threshold may vary from 5000 to 70000 depending on
your system limits and on the command executed).
\$\endgroup\$
4
  • 2
    \$\begingroup\$ That might let you think Coq is an incredibly dumb language... funny... \$\endgroup\$ Commented Jan 6, 2013 at 13:01
  • 1
    \$\begingroup\$ @leftaroundabout Actually not. The Nat type is a type level peano numeral that must act as if it is a linked list. \$\endgroup\$
    – FUZxxl
    Commented Jan 6, 2013 at 15:40
  • 1
    \$\begingroup\$ @FUZxxl: my comment was not not meant ironically at all. Decide for yourself if you want to include classical logic into that sentence, or prefer to stay constructive... \$\endgroup\$ Commented Jan 6, 2013 at 20:42
  • 2
    \$\begingroup\$ @leftaroundabout Oops... sorry. I forgot that the markdown parser always eats those nice &lt;irony&gt;-tags. \$\endgroup\$
    – FUZxxl
    Commented Jan 6, 2013 at 21:28
20
\$\begingroup\$

Java - 35

class S{static{new S();}{new S();}}
\$\endgroup\$
6
  • \$\begingroup\$ Didn't OP say no new classes? I don't see a public static void main in there. Or am I just failing to understand Java? \$\endgroup\$ Commented Feb 5, 2014 at 19:17
  • 6
    \$\begingroup\$ @B1KMusic There are no new classes, there's only one class (S). The code uses a static initializer, it throws the SO before the jvm figures out there's no main method. Works with java 6. \$\endgroup\$ Commented Feb 5, 2014 at 20:20
  • 1
    \$\begingroup\$ I understand the static block. But what is the next block ? \$\endgroup\$ Commented Jun 7, 2014 at 20:51
  • 1
    \$\begingroup\$ @NicolasBarbulesco That's an initializer block, it's executed when you construct a new instance. \$\endgroup\$ Commented Jun 8, 2014 at 6:41
  • 1
    \$\begingroup\$ @LuigiCortese I think it only works with java 6 or older \$\endgroup\$ Commented Jul 25, 2015 at 22:12
20
\$\begingroup\$

Javascript 24 characters

Browser dependent answer (must have access to apply):

eval.apply(0,Array(999999))
  • eval was the shortest global function name that I could find (anyone know of one that is shorter?)
  • apply allows us to convert an array into function parameters, the first parameter being the context of the function (this)
  • Array(999999) will create an array with the listed length. Not sure what the maximum number of arguments is, but it's less than this, and more than 99999

IE9:

SCRIPT28: Out of stack space 
SCRIPT2343: Stack overflow at line: 20 

Chrome 24:

Uncaught RangeError: Maximum call stack size exceeded 

FireFox 18

RangeError: arguments array passed to Function.prototype.apply is too large

Note — Due to the single threaded nature of javascript, infinite loops end up locking the UI and never throwing an exception.

while(1);
for(;;);

Neither of these qualify.

Update — this shaves off three characters:

eval.apply(0,Array(1e7))
\$\endgroup\$
5
  • \$\begingroup\$ MDN says that eval is the shortest. \$\endgroup\$ Commented Jan 23, 2013 at 13:30
  • 6
    \$\begingroup\$ eval.apply(0,Array(1e6)) saves 3 chars, you can even go with 9e9 at no cost \$\endgroup\$
    – ThinkChaos
    Commented Feb 2, 2014 at 22:30
  • 1
    \$\begingroup\$ apply is a standard ECMAScript feature. There is nothing browser dependent. Unless you are talking about really old browsers, but this wouldn't work in hypothetical Netscape 2 with apply anyway, because Array class doesn't exist in Netscape 2. \$\endgroup\$
    – null
    Commented Apr 2, 2014 at 12:02
  • 1
    \$\begingroup\$ new shortest in ES6: eval(...Array(9e9)) \$\endgroup\$ Commented Jan 25, 2016 at 7:36
  • 1
    \$\begingroup\$ Probably non-standard, throws in Chrome from the console. dir.apply(0,Array(1e7)); \$\endgroup\$
    – Paul J
    Commented Nov 21, 2016 at 22:05
17
\$\begingroup\$

Python 2.7 (12 chars)

exec('{'*99)

results in a «s_push: parser stack overflow»

\$\endgroup\$
4
  • 4
    \$\begingroup\$ I get SyntaxError: unexpected EOF while parsing \$\endgroup\$ Commented Jan 14, 2013 at 7:15
  • 1
    \$\begingroup\$ With exec('{'*101) I get MemoryError \$\endgroup\$ Commented Jan 14, 2013 at 7:15
  • 4
    \$\begingroup\$ In Python2, exec is a statement, so you can just use exec'{'*999 (99 doesn't seem to be enough) \$\endgroup\$
    – gnibbler
    Commented Feb 3, 2014 at 1:15
  • \$\begingroup\$ You need at least 100 to trigger a MemoryError. And that ≠ stack overflow \$\endgroup\$ Commented Sep 12, 2016 at 23:39
13
\$\begingroup\$

Mathematica, 4 chars

x=2x

$RecursionLimit::reclim: Recursion depth of 1024 exceeded. >>

\$\endgroup\$
3
  • 1
    \$\begingroup\$ "You may not define function that calls itself" \$\endgroup\$
    – Tomas
    Commented Feb 2, 2014 at 16:03
  • 14
    \$\begingroup\$ That isn't a function, it's a variable (unless it isn't at all what it looks like). \$\endgroup\$
    – A.M.K
    Commented Feb 3, 2014 at 3:12
  • \$\begingroup\$ You took my idea. \$\endgroup\$ Commented Apr 16, 2014 at 21:09
12
\$\begingroup\$

Clojure, 12 chars

(#(%%)#(%%))

Running in the repl:

user=> (#(%%)#(%%))
StackOverflowError   user/eval404/fn--407 (NO_SOURCE_FILE:1)
\$\endgroup\$
1
  • \$\begingroup\$ This reminds me of the lambda calculus expression (\x.xx)(\x.xx), but I don't know clojure well enough to tell for sure if this is what's happening. I also don't see why the aforementioned expression would result in a stack overflow, so maybe you're doing some trickery with the Y-combinator? This answer interests me and an explanation would be nice. \$\endgroup\$
    – Zwei
    Commented Sep 10, 2016 at 19:26
12
\$\begingroup\$

Java - 113 chars

I think this stays within the spirit of the "no self-calling methods" rule. It doesn't do it explicitly, and it even goes through a Java language construct.

public class S {
    public String toString() {
        return ""+this;
    }
    public static void main(String[] a) {
        new S().toString();
    }
}

Condensed Version:

public class S{public String toString(){return ""+this;}public static void main(String[] a){new S().toString();}}
\$\endgroup\$
3
  • 9
    \$\begingroup\$ Well, ""+this is actually ""+this.toString(), so the method calls itself. \$\endgroup\$
    – True Soft
    Commented Jan 19, 2013 at 8:08
  • 1
    \$\begingroup\$ @TrueSoft Pretty sure java throws in a StringBuilder object there. toString will likely be called from within there. \$\endgroup\$
    – Cruncher
    Commented Feb 18, 2014 at 21:48
  • 1
    \$\begingroup\$ By the time the compiler and optimizer are done, the toString() method ends up being public java.lang.String toString() { return this.toString(); } \$\endgroup\$ Commented Feb 23, 2014 at 19:38
12
\$\begingroup\$

C, 19 bytes

main(){int i[~0u];}
\$\endgroup\$
8
  • 4
    \$\begingroup\$ @Thomas Yes it is a stack overflow on any machine where local variables are allocated on the stack. Since the C language has no concept of a stack overflow indication (it's all undefined behavior; one of them manifests itself as a segfault), this does fit the original requirement. \$\endgroup\$
    – Jens
    Commented Feb 2, 2014 at 17:45
  • \$\begingroup\$ OK, sorry, accepted. \$\endgroup\$
    – Tomas
    Commented Feb 2, 2014 at 17:49
  • 3
    \$\begingroup\$ it gives main.c:1:16: error: size of array 'i' is negative for me on gcc 4.8.1. The unsigned version main(){int i[~0U];} works. \$\endgroup\$
    – Csq
    Commented Feb 25, 2014 at 16:00
  • \$\begingroup\$ Doesn't work for me after I manually configured a 4GB stack. \$\endgroup\$
    – FUZxxl
    Commented Oct 6, 2015 at 12:58
  • 1
    \$\begingroup\$ Nothing accesses the array, so it is not generated and no error. At least initializing or using it is necessary to error. \$\endgroup\$
    – Karl Napf
    Commented Nov 21, 2016 at 16:33
10
\$\begingroup\$

GolfScript (8 chars)

{]}333*`

Result:

$ golfscript.rb overflow.gs 
golfscript.rb:246:in `initialize': stack level too deep (SystemStackError)
from /home/pjt33/bin/golfscript.rb:130:in `new'
from /home/pjt33/bin/golfscript.rb:130:in `ginspect'
from /home/pjt33/bin/golfscript.rb:130:in `ginspect'
from /home/pjt33/bin/golfscript.rb:130:in `map'
from /home/pjt33/bin/golfscript.rb:130:in `ginspect'
from /home/pjt33/bin/golfscript.rb:130:in `ginspect'
from /home/pjt33/bin/golfscript.rb:130:in `map'
from /home/pjt33/bin/golfscript.rb:130:in `ginspect'
 ... 993 levels...
from (eval):4
from /home/pjt33/bin/golfscript.rb:293:in `call'
from /home/pjt33/bin/golfscript.rb:293:in `go'
from /home/pjt33/bin/golfscript.rb:485

Basically this creates a heavily nested data structure and then overflows the stack when trying to turn it into a string.

\$\endgroup\$
3
  • \$\begingroup\$ For me, this doesn't throw an error, but outputs [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[[[[[[[""]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] ]]]]]]]]]]]]]]]]] (and so on, output too long for comments) \$\endgroup\$
    – ProgramFOX
    Commented Feb 2, 2014 at 16:30
  • \$\begingroup\$ @ProgramFOX, there will be some value which you can replace 333 with and it will break. 333 was the smallest value which broke for me, but if you have a different version of Ruby (or maybe the same version on a different OS, for all I know) it might handle a different number of stack frames before overflowing. \$\endgroup\$ Commented Feb 2, 2014 at 22:54
  • 1
    \$\begingroup\$ Breaks at 3192 on my machine, so 6.? still works without adding characters. \$\endgroup\$
    – Dennis
    Commented Jun 26, 2014 at 22:53
10
\$\begingroup\$

x86 assembly, NASM syntax, 7 bytes

db"Pëý"

"Pëý" is 50 EB FD in hexadecimal, and

_loop:
push eax
jmp _loop

in x86 assembly.

\$\endgroup\$
8
\$\begingroup\$

Ruby, 12

eval"[]"*9e3

Gives

SystemStackError: stack level too deep

Presumably system-dependent, but you can add orders of magnitude by bumping the last digit up (not recommended).

Edit for explanation: Similarly to some other examples, this creates a string of [][][]...repeated 9000 times, then evaluates it: the rightmost [] is parsed as a function call to the rest, and so on. If it actually got to the beginning, it would throw an ArgumentError because [] is an object with a [] method that requires one argument, but my machine throws an error a little before the stack is over nine thousand.

\$\endgroup\$
6
  • \$\begingroup\$ hmm... crashed IRB :P \$\endgroup\$
    – Doorknob
    Commented Mar 22, 2013 at 23:35
  • \$\begingroup\$ Which version? ruby 1.9.2 throws “ArgumentError: wrong number of arguments (0 for 1..2)”. \$\endgroup\$
    – manatwork
    Commented Jun 1, 2013 at 11:24
  • \$\begingroup\$ Found an old ruby 1.8.7. There the posted code works as described. \$\endgroup\$
    – manatwork
    Commented Jun 1, 2013 at 11:58
  • \$\begingroup\$ Odd, it works on my 1.8.7, 1.9.2, and 1.9.3. \$\endgroup\$
    – histocrat
    Commented Jun 3, 2013 at 12:24
  • \$\begingroup\$ I would have said def f;f;end;f \$\endgroup\$
    – EMBLEM
    Commented May 6, 2015 at 19:32
8
\$\begingroup\$

Rebol (11 Chars)

do s:[do s]

Yields:

>> do(s:[do s])    
** Internal error: stack overflow
** Where: do do do do do do do do do do do do do do do do 
do do do do do do do do do do do do do do do do do do do
do do do do do do do do do do do do do do do do do do do 
do do do do do do do do do do do do do do do do do do do
do do do do do do do do do do do do do do do do do do do
do do do do do do do do do do do do do do do do do do do
do do do do do do do do do do do do do do do do do do do
do do do do do do do do do do do do do do do do do do do
do do do do do do do do do do do do do do do do do do do
do do do do do do do do do do do do do do do do do do do
do do do do do do do do do do do do...

Though Rebol has functions, closures, and objects...this doesn't define any of those. It defines a data structure, which in the code-as-data paradigm can be treated as code using DO.

We can probe into the question of "what is S" with the REPL:

>> s: [do s]
== [do s]

>> type? s
== block!

>> length? s
== 2

>> type? first s
== word!

>> type? second s
== word!

DO never turns this into a function, it invokes the evaluator in the current environment on the structure.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ +1 ... I hadn't noticed that my answer was defining a function and that was against the rules, but edited my answer to use DO...then noticed you'd already submitted that answer. So I just deleted mine, but since I'd written up why this isn't defining an object/function/closure I thought I'd put the explanation into yours. Also I think the do do do do is kind of funny and worth including. :-) Hope that's ok! \$\endgroup\$ Commented Apr 16, 2014 at 20:44
8
\$\begingroup\$

Casio Calculator, 11 keypresses

It's quite hard to count bytes/tokens in this "language" - I've given the number of keypresses required, excluding Shift, Alpha (the second shift key) and = at the end - this certainly fits into 1 byte per keypress.

Tested on the fx-85GT PLUS model, which is a standard, non-graphing, "non-programmable" scientific calculator. Other models will work.

Just stack up 11 cube roots:

3√ 3√ 3√ 3√
3√ 3√ 3√ 3√
3√ 3√ 3√

It doesn't even give a syntax error about the missing number under the square root.

This doesn't seem to work with square roots.

Alternatively, repeat cos( 31 times.

Output

Stack ERROR

[AC]  :Cancel
[<][>]:Goto

I believe that this qualifies as a stack overflow. The stack seems to be tiny...

\$\endgroup\$
2
  • \$\begingroup\$ I always thought it was called stack error because you "stacked up" too many roots :P \$\endgroup\$
    – FlipTack
    Commented Nov 21, 2016 at 15:13
  • \$\begingroup\$ My Canon calculator gives a stack error with just about any operator (excluding at least +, -, * and /) if it is repeated 25 times or more. For instance, this causes stack error (without syntax error): ((((((((((((((((((((((((( \$\endgroup\$
    – Steadybox
    Commented Dec 3, 2016 at 19:13
7
\$\begingroup\$

C, 35 characters

main(){for(;;)*(int*)alloca(1)=0;}
\$\endgroup\$
20
  • \$\begingroup\$ Why store anything in the assigned space? \$\endgroup\$ Commented Jan 5, 2013 at 17:15
  • 1
    \$\begingroup\$ In this case, it's impossible to solve this problem in C. \$\endgroup\$
    – FUZxxl
    Commented Jan 6, 2013 at 15:41
  • 3
    \$\begingroup\$ @dmckee, Not all segmentation faults are stack overflows, but I'd say this one is, since it's the result of exceeding the stack capacity. \$\endgroup\$
    – ugoren
    Commented Jan 6, 2013 at 19:12
  • 1
    \$\begingroup\$ @dmckee, alloca allocates from the stack. \$\endgroup\$
    – ugoren
    Commented Jan 6, 2013 at 19:15
  • 1
    \$\begingroup\$ @PeterTaylor: It probably depends on the implementation but in my case alloca(1) is basically translated to sub $1, %esp so the stack isn't touched. \$\endgroup\$
    – mtvec
    Commented Jan 7, 2013 at 14:48
7
\$\begingroup\$

Common Lisp, 7 characters

#1='#1#
\$\endgroup\$
4
  • \$\begingroup\$ Beautiful...I was planning to use #1=(#1#) for the terminal and (print #1=(#1#)), but your solution is so much better. \$\endgroup\$
    – protist
    Commented Nov 19, 2013 at 16:29
  • \$\begingroup\$ Actually that doesn't overflow at read time, only when you attempt to print it. So aside from the 1 character difference, yours is no better. \$\endgroup\$
    – protist
    Commented Nov 19, 2013 at 16:31
  • \$\begingroup\$ You're right, just edited that out. I'm not sure if there's a way to cause an overflow at read-time. \$\endgroup\$ Commented Jan 11, 2014 at 22:04
  • \$\begingroup\$ Actually, #.#1='#1# causes a read-time overflow :-) \$\endgroup\$ Commented Apr 27, 2014 at 22:26
7
\$\begingroup\$

Python - 11 chars

exec'('*999

>>> exec'('*999
s_push: parser stack overflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
MemoryError
\$\endgroup\$
1
  • \$\begingroup\$ Very clever solution. \$\endgroup\$
    – mbomb007
    Commented Feb 24, 2015 at 14:54
7
\$\begingroup\$

FORTH, 13 bytes

BEGIN 1 AGAIN

overflows the value stack

\$\endgroup\$
3
  • \$\begingroup\$ : X X ; X (9) must overflow return stack \$\endgroup\$
    – AMK
    Commented Jan 18, 2013 at 14:45
  • \$\begingroup\$ won't work (X isn't defined while defining the call and that's a self reference/recursion \$\endgroup\$ Commented Jan 18, 2013 at 14:50
  • \$\begingroup\$ @ratchetfreak, those control words can only be used in a compile state, so they need to be wrapped in a :...; word definition. That adds at least 6 characters, plus at least 2 more for this to execute as a program. You might be able to do it shorter, but here's an example: : F BEGIN 1 AGAIN ; F. I suggest this because the question asks: "Write a program." Anyways, gave you an upvote for Forth, regardless of char count! :-) \$\endgroup\$ Commented Jan 4, 2014 at 18:08
6
\$\begingroup\$

Postscript, 7

{1}loop

Eg.

$ gsnd
GPL Ghostscript 9.06 (2012-08-08)
Copyright (C) 2012 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
GS>{1}loop
Error: /stackoverflow in 1
Operand stack:
   --nostringval--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   %loop_continue   --nostringval--   --nostringval--   false   1   %stopped_push   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   %loop_continue
Dictionary stack:
   --dict:1168/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
Current file position is 8
GS<1>
\$\endgroup\$
6
\$\begingroup\$

Haskell (GHC, no optimization), 25

main=print$sum[1..999999]

sum is lazy in the total. This piles up a bunch of thunks, then tries to evaluate them all at the end, resulting in a stack overflow.

\$\endgroup\$
2
5
\$\begingroup\$

PHP 5.4, 33 characters

for($n=1e5;$n--;)$a=(object)[$a];

This causes a stack overflow when the nested stdClass objects are automatically destroyed:

$ gdb -q php
Reading symbols from /usr/bin/php...(no debugging symbols found)...done.
(gdb) set pagination 0
(gdb) r -nr 'for($n=1e5;$n--;)$a=(object)[$a];'
Starting program: /usr/bin/php -nr 'for($n=1e5;$n--;)$a=(object)[$a];'
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00000000006debce in zend_objects_store_del_ref_by_handle_ex ()
(gdb) bt
#0  0x00000000006debce in zend_objects_store_del_ref_by_handle_ex ()
#1  0x00000000006dee73 in zend_objects_store_del_ref ()
#2  0x00000000006a91ca in _zval_ptr_dtor ()
#3  0x00000000006c5f78 in zend_hash_destroy ()
#4  0x00000000006d909c in zend_object_std_dtor ()
#5  0x00000000006d9129 in zend_objects_free_object_storage ()
#6  0x00000000006dee53 in zend_objects_store_del_ref_by_handle_ex ()
#7  0x00000000006dee73 in zend_objects_store_del_ref ()
#8  0x00000000006a91ca in _zval_ptr_dtor ()
#9  0x00000000006c5f78 in zend_hash_destroy ()
#10 0x00000000006d909c in zend_object_std_dtor ()
#11 0x00000000006d9129 in zend_objects_free_object_storage ()
[...]
#125694 0x00000000006dee53 in zend_objects_store_del_ref_by_handle_ex ()
#125695 0x00000000006dee73 in zend_objects_store_del_ref ()
#125696 0x00000000006a91ca in _zval_ptr_dtor ()
#125697 0x00000000006c5f78 in zend_hash_destroy ()
#125698 0x00000000006d909c in zend_object_std_dtor ()
#125699 0x00000000006d9129 in zend_objects_free_object_storage ()
#125700 0x00000000006dee53 in zend_objects_store_del_ref_by_handle_ex ()
#125701 0x00000000006dee73 in zend_objects_store_del_ref ()
#125702 0x00000000006a91ca in _zval_ptr_dtor ()
#125703 0x00000000006c4945 in ?? ()
#125704 0x00000000006c6481 in zend_hash_reverse_apply ()
#125705 0x00000000006a94e1 in ?? ()
#125706 0x00000000006b80e7 in ?? ()
#125707 0x0000000000657ae5 in php_request_shutdown ()
#125708 0x0000000000761a18 in ?? ()
#125709 0x000000000042c420 in ?? ()
#125710 0x00007ffff5b6976d in __libc_start_main (main=0x42bf50, argc=3, ubp_av=0x7fffffffe738, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe728) at libc-start.c:226
#125711 0x000000000042c4b5 in _start ()
\$\endgroup\$
1
  • 2
    \$\begingroup\$ +1 for what must be PHP's second appearance on CodeGolf! \$\endgroup\$
    – Bojangles
    Commented Apr 11, 2013 at 13:53
5
\$\begingroup\$

Q/k (16 chars)

Not sure if this is in the spirit of the challenge but I don't think it breaks the rules:

s:{f`};f:{s`};f`
\$\endgroup\$
1
  • \$\begingroup\$ It's a shame C# requires so much typing, you inspired my answer! \$\endgroup\$ Commented Apr 8, 2013 at 18:59
5
\$\begingroup\$

A bunch in the same style:

Python, 30

(lambda x:x(x))(lambda y:y(y))

Javascript, 38

(function(x){x(x)})(function(y){y(y)})

Lua, 44

(function(x) x(x) end)(function(y) y(y) end)
\$\endgroup\$
6
  • \$\begingroup\$ In Python x=lambda y:y(y);x(x) is shorter (20 chars). This function is not recursive. x calls any function passed to it as an argument. \$\endgroup\$
    – AMK
    Commented Apr 17, 2013 at 16:28
  • \$\begingroup\$ Ruby 2.0 - ->x{x[x]}[->y{y[y]}] \$\endgroup\$ Commented Nov 1, 2013 at 12:10
  • \$\begingroup\$ Mathematica #@#&[#@#&] \$\endgroup\$
    – alephalpha
    Commented Nov 13, 2013 at 14:57
  • \$\begingroup\$ You're just using recursion, then why not do just that, for example in JS: (function x(){x()})() ? \$\endgroup\$
    – xem
    Commented Jan 1, 2014 at 14:29
  • \$\begingroup\$ @xem Requirements say no recursion, that is why. \$\endgroup\$
    – Danny
    Commented Feb 14, 2014 at 13:16
5
\$\begingroup\$

C#: 106 86 58 46 32 28

32: Getters can SO your machine easy in C#:

public int a{get{return a;}}
\$\endgroup\$
6
  • 1
    \$\begingroup\$ No need for setter public int a {get{return a;}} \$\endgroup\$
    – Mike Koder
    Commented Apr 10, 2013 at 10:35
  • 3
    \$\begingroup\$ This violates the rule "You are not allowed to define a function which calls itself". Admittedly it's hidden behind syntax sugar, but it's still missing the point of the challenge. \$\endgroup\$ Commented Apr 11, 2013 at 13:08
  • \$\begingroup\$ Adding the setter somewhat circumvents the rule, because you now have two functions calling each other. But I wonder: does that still violate the OP's intentions behind this challenge? \$\endgroup\$ Commented Apr 11, 2013 at 13:10
  • 1
    \$\begingroup\$ The idea as I understand it is to find some excessively nested recursion in the interpreter or standard API of the language. This might not be too easy in C#. \$\endgroup\$ Commented Apr 13, 2013 at 21:21
  • 1
    \$\begingroup\$ Why "public string"? "int" works just as well: int a { get { return a; } } \$\endgroup\$
    – NPSF3000
    Commented Nov 9, 2013 at 11:16
5
\$\begingroup\$

LaTeX: 8 characters

\end\end

This is the same code used in this answer. Essentially, the \end macro expands itself repeatedly, resulting in a stack overflow: TeX capacity exceeded, sorry [input stack size=5000]. A more detailed explanation can be found here.

\$\endgroup\$
5
\$\begingroup\$

INTERCAL, 12 bytes

(1)DO(1)NEXT

Explanation:

NEXT is INTERCAL's version of a subroutine call (or, at least, the closest you can get). It pushes the current position onto the NEXT stack and jumps to the given label.

However, if the NEXT stack length exceeds 80, you get what's pretty much the INTERCAL version of a stack overflow:

ICL123I PROGRAM HAS DISAPPEARED INTO THE BLACK LAGOON
    ON THE WAY TO 1
        CORRECT SOURCE AND RESUBNIT

Try it on Ideone..

\$\endgroup\$
1
  • 6
    \$\begingroup\$ "HAS DISAPPEARED INTO THE BLACK LAGOON" what is this, ArnoldC? \$\endgroup\$ Commented Jan 24, 2016 at 12:28
5
\$\begingroup\$

Mornington Crescent, 139 133

Take Northern Line to Bank
Take Circle Line to Temple
Take Circle Line to Temple
Take Circle Line to Bank
Take Northern Line to Angel
\$\endgroup\$
4
\$\begingroup\$

X86 assembly (AT&T), 33 characters

Note that although I'm using the label main as a jump target, this is not a recursive function.

.globl main
main:push $0;jmp main
\$\endgroup\$
2
  • \$\begingroup\$ Nice idea: this is a sort of recursion-without-recursion! \$\endgroup\$ Commented Jan 9, 2013 at 21:29
  • \$\begingroup\$ using a86: dd 0fdeb60 10 characters! \$\endgroup\$
    – Skizz
    Commented Jan 15, 2013 at 16:17
4
\$\begingroup\$

Python (17):

c='exec c';exec c
\$\endgroup\$
1
  • \$\begingroup\$ hm, I get KeyError: 'unknown symbol table entry' \$\endgroup\$
    – stefreak
    Commented Dec 12, 2017 at 22:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.