Everything2
Near Matches
Ignore Exact
Full Text
Everything2

for(int *p=0;;*(p++)=0);

created by mcc

(thing) by mcc (2.7 y) (print)   ?   (I like it!) 2 C!s Mon Jul 24 2000 at 22:06:19

This single statement is the quickest, most elegant, most portable way i have seen yet to produce a crash. It is a bit of C++ code that, when executed, attempts to begin at memory address zero and, starting there, rewrite the entire contents of memory with zeroes. The nature of the resulting crash varies from OS to OS.

Linux and other UNIX-like systems, with their full, complete memory protection, will simply emit Segmentation fault (core dumped) and continue working as they did before. To see this quickly demonstrated on a linux box, try entering the following at the command line (assuming you're using Bash):
echo "void main(){for(int *p=0;;*(p++)=0);}">crash.cpp;g++ crash.cpp -o crash;./crash;

On the Mac OS, where there is no protected memory whatsoever, the loop will result in the entire system locking up completely. You won't even be able to move the mouse. On most of the newer macs, you won't even be able to reset by normal methods, and may have to actually unplug the computer if it's one of the early iMacs. If you're lucky enough to have an emergency reset button on the case, it will work. (Mac OS X, meanwhile, will simply kill the process and give an unexpected quit message, since it is technically BSD UNIX.)

On Windows NT and Windows 9x, you will get an error along the lines of "This program has performed an illegal operation and will be shut down". Note, however, that this does not mean has real memory protection. It doesn't. Windows NT (AKA "Windows 2000" or "Windows XP") does, but any OS based on the 9x kernel (including 95, 98 and Windows Millennium) does not. For details on this, as well as a variation on the code which will lock up Win9x completely, see my node Windows 9x does not have true memory protection.
I haven't tried the Loop yet in MS-DOS but i'd imagine the results are pretty nasty.

Note that the for loop given is C++ code and will not work in C. C will not allow variable initialization in the initialization of a for loop. For a c-friendly version, try:
void main(){int *p=0;for(;;)*(p++)=0;}


printable version
chaos

Windows 9x does not have true memory protection I'm scared to run the program I wrote Stupid Unix Tricks *ptr++
Stupidest thing you've coded just to see if you could death code overflowing C *n?x
The quickest way to crash Windows 9x This program has performed an illegal operation and will be shut down Signal to meta-signal ratio Windows Millennium
BSD Hello World Mac OS X Null pointer
Segmentation fault Memory management :(){:|:&};: MS-DOS
protected memory Snoop Doggy Dogg Windows XP Packing the perfect narghila head
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Look at this mess the Death Borg made!
Suggestions for E2
coalition of the willing
Vivien Leigh
Mexican red rice
Inhale. Kill. Exhale.
eBay
On becoming a parent
The Satanic Verses
Enigma
August and Everything After
Jack London witnesses the San Francisco earthquake
Things I've yet to fully learn
warp core
New Writeups
antigravpussy
One fly amongst many(person)
sam512
Moon Base Shackleton, 1978(fiction)
Pavlovna
toy boy(person)
XWiz
tear jerker(review)
Heitah
Anarchy is Order(idea)
jessicaj
July 26, 2008(dream)
Berek
ABBA(person)
devolution
k-hole(place)
Nadine_2
The Sound Of Madness(review)
SwimmingMonkey
Conversations with Fo Fo, the Loneliest dog in Purgatory(fiction)
locke baron
lynx(thing)
Simulacron3
Reality, Dimensions and the Natural Ontology(essay)
SubSane
Making Love to a 9-Foot Woman(person)
Ouzo
Thoughts(idea)
antigravpussy
I fall silent, listening. The breadcrumbs are talking about us(person)
This affordable entertainment brought to you by The Everything Development Company