Ian's Humor Pages
"Poem.c"

by Ian Kluft, 1986

I wrote this in 1986, originally intending to submit it for the Obfuscated C Programming Contest. I was a junior in college at the time and got too busy with school projects to actually send it in. Oh well, it's fun reading anyway.

/*
 *      An example of the C preprocessor in use
 *      by Ian Kluft
 *
 *      Judicious use of the preprocessor can make C programs readable
 *      by anyone.
 */

#define         TIMES   5000
#define         a       pi +=
#define         as      < TIMES
#define         black   2 )
#define         bowl    }
#define         coal    )
#define         dog     ( sign *= -1 );
#define         fleas   ctr
#define         had     {
#define         left    ;
#define         little  4.0 / ctr *
#define         Mary    main()
#define         out     printf ( "pi = %.10lf\n", pi );
#define         the     if ((
#define         to      return;
#define         went    -= 2 ) == 1 )
#define         were    +=
#define         whose   if ((
#define         and
#define         every
#define         time
#define         that

int     ctr = 1,
        sign = -1;

double  pi = 0.0;

Mary
had
        a little dog
        whose fleas were black as coal and every time that
                Mary left
        the fleas went
                out
        to
bowl


/*
 *      which translates into a program which calculates pi
 *
 *      preprocessed listing follows
 *

int     ctr = 1,
        sign = -1;

double  pi = 0.0;

main()
{
        pi += 4.0 / ctr * ( sign *= -1 );
        if (( ctr += 2 ) < 5000 )    
                main() ;
        if (( ctr -= 2 ) == 1 )
                printf ( "pi = %.10lf\n", pi );
        return;
}

 *
 */


Back up to Ian's Humor Pages