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

Don Johe picture Don Johe · Nov 20, 2009 · Viewed 11.4k times · Source

This is a little bit of fun. Can you devise the shortest program which compiles but does nothing but immediately crash when executed? Wherefore by "crash" we mean that the program stops with an error condition (a core dump for example).

Is there a language that crashes faster (7 chars) than C using a gcc compiler? [I leave this answer for somebody to find.]

(It should be allowable to use compiler flags. Otherwise 7 wouldn't work nowadays, compiler checks became much better.)

[evaluation of results] I am unable to mark a single answer because there are multiple correct ones for multiple languages. It would not be fair to disqualify one answer for another. Please use votes for choosing best answers.

Answer

Aaron picture Aaron · Nov 20, 2009

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)
$