Worst abuse of the C preprocessor Contest 1986 (IOCCC)

Andres Pulido
4 min readJul 15, 2020

IOCCC (The International Obfuscated C Code Contest) is an annual programming contest with an obfuscated C code.

In 1986 at the IOCCC they had a winner in which the category was “worst abuse of the C preprocessor”. This winner was Jim Hague in which his code was exotic.

What is the obfuscated code?

It is basically a machine code that is deliberately written and can be hardly de understood by humans, is usually used for different purposes such as increasing the security of what you want to transmit.

Letter of award recognition of Worst abuse of the C preprocessor

Worst abuse of the C preprocessor
Jim Hague
University of Kent at Canterbury
Canterbury, Kent
UK
Judges’ comments:

Compile this program and feed ASCII text into standard input. This program is known to pass lint on some systems and abort lint on others.
This program was selected for the 1987 t-shirt collection.
Think morse code when you ponder this program. Note how the use of similar variables can be obfuscating! The author notes that this program implements the international morse standard. Now for extra credit, what morse message does the program spell out?

What is Morse code?

Morse code is a method used in telecommunication to encode text characters as standardized sequences of two different signal duration, called dots and dashes or dits and dahs. Morse code is named after Samuel Morse, an inventor of the telegraph.

The International Morse Code encodes the 26 English letters A through Z, some non-English letters, the Arabic numerals and a small set of punctuation and procedural signals. There is no distinction between upper and lower case letters. Each Morse code symbol is formed by a sequence of dots and dashes. The dot duration is the basic unit of time measurement in Morse code transmission. The duration of a dash is three times the duration of a dot. Each dot or dash within a character is followed by a period of signal absence, called a space, equal to the dot duration.

The obfuscated code created by Jim Hague (1986)

#define DIT (
#define DAH )
#define __DAH ++
#define DITDAH *
#define DAHDIT for
#define DIT_DAH malloc
#define DAH_DIT gets
#define _DAHDIT char
_DAHDIT _DAH_[]="ETIANMSURWDKGOHVFaLaPJBXCYZQb54a3d2f16g7c8a90l?e'b.s;i,d:"
;main DIT DAH{_DAHDIT
DITDAH _DIT,DITDAH DAH_,DITDAH DIT_,
DITDAH _DIT_,DITDAH DIT_DAH DIT
DAH,DITDAH DAH_DIT DIT DAH;DAHDIT
DIT _DIT=DIT_DAH DIT 81 DAH,DIT_=_DIT
__DAH;_DIT==DAH_DIT DIT _DIT DAH;__DIT
DIT'\n'DAH DAH DAHDIT DIT DAH_=_DIT;DITDAH
DAH_;__DIT DIT DITDAH
_DIT_?_DAH DIT DITDAH DIT_ DAH:'?'DAH,__DIT
DIT' 'DAH,DAH_ __DAH DAH DAHDIT DIT
DITDAH DIT_=2,_DIT_=_DAH_; DITDAH _DIT_&&DIT
DITDAH _DIT_!=DIT DITDAH DAH_>='a'? DITDAH
DAH_&223:DITDAH DAH_ DAH DAH; DIT
DITDAH DIT_ DAH __DAH,_DIT_ __DAH DAH
DITDAH DIT_+= DIT DITDAH _DIT_>='a'? DITDAH _DIT_-'a':0
DAH;}_DAH DIT DIT_ DAH{ __DIT DIT
DIT_>3?_DAH DIT DIT_>>1 DAH:'\0'DAH;return
DIT_&1?'-':'.';}__DIT DIT DIT_ DAH _DAHDIT
DIT_;{DIT void DAH write DIT 1,&DIT_,1 DAH;}

If we do compile the code above in our GCC compiler would yell at us with the following:

Andrew@ubuntu:$ gcc hague.c -o h
hague.c:10:2: warning: return type defaults to ‘int’ [-Wimplicit-int]
;main DIT DAH{_DAHDIT
^
hague.c: In function ‘main’:
hague.c:6:17: warning: conflicting types for built-in function ‘malloc’
#define DIT_DAH malloc
^
hague.c:12:24: note: in expansion of macro ‘DIT_DAH’
DITDAH _DIT_,DITDAH DIT_DAH DIT
^
hague.c:15:35: warning: implicit declaration of function ‘__DIT’ [-Wimplicit-function-declaration]
__DAH;_DIT==DAH_DIT DIT _DIT DAH;__DIT
^
hague.c:18:7: warning: implicit declaration of function ‘_DAH’ [-Wimplicit-function-declaration]
_DIT_?_DAH DIT DITDAH DIT_ DAH:'?'DAH,__DIT
^
hague.c: At top level:
hague.c:25:6: warning: return type defaults to ‘int’ [-Wimplicit-int]
DAH;}_DAH DIT DIT_ DAH{ __DIT DIT
^
hague.c: In function ‘_DAH’:
hague.c:25:6: warning: type of ‘DIT_’ defaults to ‘int’ [-Wimplicit-int]
hague.c: At top level:
hague.c:27:17: warning: return type defaults to ‘int’ [-Wimplicit-int]
DIT_&1?'-':'.';}__DIT DIT DIT_ DAH _DAHDIT
^
hague.c: In function ‘__DIT’:
hague.c:28:20: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
DIT_;{DIT void DAH write DIT 1,&DIT_,1 DAH;}
^
/tmp/ccG1Yh1A.o: In function `main':
hague.c:(.text+0x14a): warning: the `gets' function is dangerous and should not be used.
Andrew@ubuntu:~/c/ioccc$ ./h

It will warn us with plenty of errors but an executable file “.h” is created, and we can execute it with the following command “./h”

Once executed the program transforms ASCII text to morse code,
In this case, will provide to the terminal the following phrase to translate into Morse code: “Every shot you don’t take is a shot you miss”

vagrant@Andrew-ubuntu-trusty-64:~/holbertonschool-low_level_programming/0x0D-preprocessor$ ./h
"Every shot you don't take is shot you miss"
? . ...- . .-. -.-- ? ... .... --- - ? -.-- --- ..- ? -.. --- -. .-..-. - ? - .- -.- . ? .. ... ? ... .... --- - ? -.-- --- ..- ? -- .. ... ... ?

Isn’t this wonderful? but we can come in to a conclusion that writing code that looks obscure or obfuscated is not a good practice at all. Code that overuses statements rather than structured programming constructs, resulting in convoluted and unmaintainable programs

Writing code could sometimes be a very difficult part of any software development process. So it is better to organize everything especially for big projects, otherwise the coding processes and code management afterwards may end up not only consuming but also a big headache.

Please follow these tips for better practices:

  1. Use a Coding Standard
  2. Write Useful Comments
  3. Avoid Global Code
  4. Use Meaningful Names
  5. Meaningful Structures
  6. Try a Version Control Software
  7. Use a Testing Framework

If you have any questions, comments or suggestions, feel free to contact me on Twitter @MrTechi_

--

--