C Abuse

C Abuse

By Thaddaeus Frogley

Overload, 13(65):, February 2005


[Editorial note: I have often stated that one must consider the intended audience in any piece of writing. I've also been known to point out that code is a form of writing and that the principal audience, in this case, is not the compiler. This article demonstrates just how much the style of code can be affected by inverting the usual assumption that the intent is to communicate what the code does to your audience. - Alan]

Four years ago I collaborated on the THADGAVIN [ thadgavin ] entry to the International Obfuscated C Code Contest [ ioccc ]. It won an award (Most Portable Output), but it was a behemoth, only just scraping inside the maximum size limit for the contest. Much of its complexity was inherent in the algorithm, the obfuscation was a straightforward refactoring, and the reason for the award was mostly due to the use of a cross platform library. In conclusion, while it was a winner, in the end I was not happy with the "art" of the code.

The following year I wrote another entry. This time I wanted to do something functional and minimalist, something with a strong theme, and something self-referential. I had striven, and in my opinion failed, to make the 2000 entry a visual as well as an intellectual appeal. I wanted to do the same again in 2001, but again I wanted to be minimalist. I wanted to create a piece of code that could be considered to be "art" on multiple levels. So here, for your pleasure, I present my short (untitled) program:

/*(c) 2001 Thad */
#include<string.h>
#include <stdio.h>
#define abc stdout
int main(int a,ch\
ar*b){char*c="??="
"??(??/??/??)??'{"
"??!??>??-";while(
!((a=fgetc(stdin))
==EOF))fputc((b=s\
trchr(c,a))?fputc(
fputc(077,abc),abc
),"=(/)'<!>""-"??(
b-c??):a, abc);??>

I encourage you to study it. Try to work out what it does without compiling and running it.

Now, assuming you've worked out what it does, can you work out how many sins are committed in these 14 short lines of code? How many good practice guidelines are broken?

References

[thadgavin] http://thad.notagoth.org/thadgavin/

[ioccc] http://www.ioccc.org/

[apple] http://developer.apple.com/documentation/DeveloperTools/gcc-3.3/cpp/Initial-processing.html






Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.