Programmer's Wiki

The International Obfuscated C Code Contest (abbr. IOCCC) is a Programming contest for the most creatively obfuscated C (programming language) Code held annually since 1984 (with the exception of 1997, 1999, 2002, 2003, and 2006). There are many winning entries each year, and each entry gets a category such as "Worst Abuse of the C preprocessor" or "Most Erratic Behavior".

The IOCCC was started by Landon Curt Noll and Larry Bassel. They were talking together about the horrible code it was their jobs to maintain. They decided to hold a contest for the worst possible C code. Within the code size limit of only a few kilobytes, the contestants manage to do complicated things — a 2004 winner turned out an operating system .

Some quotes from 2004 winners include:

  • To keep things simple, I have avoided the C preprocessor and tricky statements such as "if", "for", "do", "while", "switch", and "goto".
  • We still aren't sure whether or not this is a useful program, but it's the first atomic fission we've seen in the IOCCC.
  • Why not use the program to hide another program in the program? It must have seemed reasonable at the time.
  • The program implements an 11-bit ALU in the C preprocessor.
  • I found that calculating prime numbers up to 1024 makes the program include itself over 6.8 million times.
 #define _ -F<00||--F-OO--;
 int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()

(Note that the entry was written in K&R C; it doesn't work correctly in ANSI C without some change.)

Another good example is this clever flight simulator, the winner of the IOCCC in 1998 as shown below:

 #include                                     <math.h>
 #include                                   <sys/time.h>
 #include                                   <X11/Xlib.h>
 #include                                  <X11/keysym.h>
                                           double L ,o ,P
                                          s[999],E,h= 8,I,
                                         1E3,r,t, u,v ,W,S=
                                         a,B,A=32.2,c, F,H;
                                         int N,q, C, y,p,U;
                                        Window z; char f[52]
                                     ; GC k; main(){ Display*e=
  XOpenDisplay( 0); z=RootWindow(e,0); for (XSetForeground(e,k=XCreateGC (e,z,0,0),BlackPixel(e,0))
 ; scanf("%lf%lf%lf",y +n,w+y, y+s)+1; y ++); XSelectInput(e,z= XCreateSimpleWindow(e,z,0,0,400,400,
 0,0,WhitePixel(e,0) ),KeyPressMask); for(XMapWindow(e,z); ; T=sin(O)){ struct timeval G={ 0,dt*1e6}
 ; K= cos(j); N=1e4; M+= H*_; Z=D*K; F+=_*P; r=E*K; W=cos( O); m=K*W; H=K*T; O+=D*_*F/ K+d/K*E*_; B=
 sin(j); a=B*T*D-E*W; XClearWindow(e,z); t=T*E+ D*B*W; j+=d*_*D-_*F*E; P=W*E*B-T*D; for (o+=(I=D*W+E
 *T*B,E*d/K *B+v+B/K*F*D)*_; p<y; ){ T=p[s]+i; E=c-p[w]; D=n[p]-L; K=D*m-B*T-H*E; if(p [n]+w[ p]+p[s
 ]== 0|K <fabs(W=T*r-I*E +D*P) |fabs(D=t *D+Z *T-a *E)> K)N=1e4; else{ q=W/K *4E2+2e2; C= 2E2+4e2/ K
  *D; N-1E4&& XDrawLine(e ,z,k,N ,U,q,C); N=q; U=C; } ++p; } L+=_* (X*t +P*M+m*l); T=X*X+ l*l+M *M;
   XDrawString(e,z,k ,20,380,f,17); D=v/l*15; i+=(B *l-M*r -X*Z)*_; for(; XPending(e); u *=CS!=N){
                                    XEvent z; XNextEvent(e ,&z);
                                          N-LT? UP-N?& E:&
                                          J:& u: &h); --*(
                                          DN -N? N-DT ?N==
                                          RT?&u: & W:&h:&J
                                           ); } m=15*F/l;
                                           c+=(I=M/ l,l*H
                                           +I*M+a*X)*_; H
                                            )/S; K=F*M+(
                                            h* 1e4/l-(T+
                                            a=2.63 /l*d;
                                            X+=( d*l-T/S
                                             *(.19*E +a
                                             )-M* v +A*
                                             Z)*_; l +=
                                             K *_; W=d;
                                             "%5d  %3d"
                                             "%7d",p =l
                               O*57.3)%0550,(int)i); d+=T*(.45-14/l*
                              X-a*130-J* .14)*_/125e2+F*_*v; P=(T*(47
                              *I-m* 52+E*94 *D-t*.38+u*.21*E) /1e2+W*
                              179*v)/2312; select(p=0,0,0,0,&G); v-=(
                                )/107e2)*_; D=cos(o); E=sin(o); } }

Some ways in which contributions are notable include:

  • The appearance of the source code, which may resemble images, text, etc.
  • Preprocessor redefinitions to make code harder to read
  • Self-modifying code
  • Worst abuse of the rules. In several years, an entry was submitted that was so patently absurd that it required a new definition of some of the rules for the next year. This, of course, is a high honor. An example is the world's shortest Quine (computing). The entry was a program zero bytes in length that if run printed zero bytes to the screen (this requires some creative use of the Makefile to get it right).

The nature of this contest has naturally resulted in programs which skirt around the edges of C standards, or result in constructs which trigger rarely used code path combinations in compilers. As a result, several of the past entries may not compile directly in a modern compiler, and some may even cause crashes.

See also[]

Notes and references[]

External links[]

Smallwikipedialogo.png This page uses content from Wikipedia. The original article was at International Obfuscated C Code Contest. The list of authors can be seen in the page history. As with the Programmer's Wiki, the text of Wikipedia is available under the GNU Free Documentation License.