Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jdee/xmas

Restoration of a classic K&R C program
https://github.com/jdee/xmas

c k-and-r

Last synced: 2 months ago
JSON representation

Restoration of a classic K&R C program

Awesome Lists containing this project

README

        

This is without a doubt one of the greatest computer programs ever written
and will forever stand as a monument to skill and artistry in defiance of
standards, maintainability and productivity. Note the entire program is a
single line of code.

It is regrettably difficult to compile K&R C in 2019, so I've updated it to
ANSI C to build and run cleanly with GCC, Clang & Visual C.

Some changes were necessary to compile. Others suppress warnings without
resorting to compiler options or pragmata. All changes have been made in
limited ways to minimize the intrusion and preserve the opacity and spirit
of the original code.

This surgery is limited to
1. Some preprocessor directives and a typedef before main() for the purpose of
type conversion.
2. Conversion of argument syntax from K&R to ANSI.
3. Conformity with the ANSI signature of main().
4. Some stack variables at the start of main to facilitate type safety
and conformity.
5. Explicitly casting the return value of main.

Jimmy Dee
July 23, 2019

To build and run, simply type:

Unix:
```bash
make hay
```

Windows:
```
cl xmas.c
xmas
```
or use the Visual Studio Solution xmas.sln in the repo.

The original K&R:
```c
/*
LEAST LIKELY TO COMPILE SUCCESSFULLY:
Ian Phillipps, Cambridge Consultants Ltd., Cambridge, England

An appropriate program for December 25th, this consists primarily of
calls to main() combined by a lot of the ternary conditional (?:)
operators. Have you ever seen a more forceful return? The judges note
that this program looked like what you would get by pounding on the keys
of a type writer at random.

Note -- I have made a minor correction (for spelling) to line 47, where I
added a missing comma at column 59.
*/

main(t,_,a)
char
*
a;
{
return!

0