Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code-Golf: What is the shortest program that compiles and crashes?

Bah - I can crash C in 5 characters:

main;

This declares an implicit int variable called 'main'. It's global so the variable has an initial value of 0. It's C the names aren't decorated - so the linker doesn't realize that it's a var and not a function.

GCC gave me a warning - but that's all.

$ gcc crash.c 
crash.c:1: warning: data definition has no type or storage class
$ ./a.exe
Segmentation fault (core dumped)
$

Crash with 0 characters:

$ > golf.c
$ gcc -Wl,--defsym=main=0 golf.c
$ ./a.out
Segmentation fault

I wonder if this counts...

a

This is in JavaScript. This gives the runtime error of "object not found". Since JavaScript is a dynamic language, syntactically this is actually correct. Still feels like twisting the rules. :P


using python:

1/0

X86 machine code: 1 byte

From cmd prompt in windows create file a.com containing byte F4, x86 halt instruction:

F:\>debug
-a 100
0BFD:0100 hlt
0BFD:0101
-r cx
CX 0000
:1
-n a.com
-w
Writing 00001 bytes
-q

F:\>a.com

The NTVDM CPU has encountered illegal instruction


$ cat > crash.S
hlt
$ as -o crash.o crash.S
$ ld crash.o
ld: warning: cannot find entry symbol _start; defaulting to 0000000008048054
$ ./a.out
Segmentation fault

Perl

die
Died at test line 1.

die

prints the value of LIST to STDERR and exits with the current value of $! (errno).