Merge pull request #1568 from xexyl/goren2011

This commit is contained in:
Landon Curt Noll authored and GitHub committed 2023-11-27 12:21:44 -07:00
commit a4e4bc2f04
4 files changed
+51 -11

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

+10 -10
View File
@@ -15,7 +15,7 @@ echo "some text" | ./goren
### Try:
```sh
echo "Hello, world!" | ./goren
./try.sh
```
@@ -23,7 +23,7 @@ echo "Hello, world!" | ./goren
In the words of [René François Ghislain Magritte Magritte](http://en.wikipedia.org/wiki/Rene_Magritte):
![This is not a pipe](http://upload.wikimedia.org/wikipedia/en/b/b9/MagrittePipe.jpg "Ceci n'est pas une pipe")
![This is not a pipe](MagrittePipe.jpg "Ceci n'est pas une pipe")
One may ask the surrealist question:
@@ -65,18 +65,17 @@ stuffing data.
One thing I tried to achieve is condition free programming. Many
have noted that conditions make the code harder to read and understand.
A good example would be:
[Brent Burley's 2004 IOCCC winner](/2004/burley/burley.c).
A good example would be: [Brent Burley's 2004 IOCCC
winner](/2004/burley/README.md).
That entry omits conditional statements such as `if` and `while`.
His achievement in improving clarity by omitting conditions is
impressive, but I think it can be taken further, in two ways.
First, conditional operators, such as `?:`, `&&` and `||`, can be thrown
away. Second, using `setjmp` and `longjmp`, which are unfortunately
not in common use, might make it difficult for a novice programmer
to understand the code without referring to the man page.
First, conditional operators, such as `?:`, `&&` and `||`, can be thrown away.
Second, using `setjmp(3)` and `longjmp(3)`, which are unfortunately not in
common use, might make it difficult for a novice programmer to understand the
code without referring to the man page.
By removing these, the code is 100% condition free, and every
function runs its instructions in perfect order. Naturally, this
@@ -84,12 +83,13 @@ makes the program flow trivial to understand. This can be verified
by disassembling the compiled code and looking for conditional jumps
(when compiled with gcc on x86, there are none).
### Compatibility:
The program should compile with any C compiler, but was tested
mostly with gcc on Linux.
It doesn't support 64 bits (due to integer-pointer casts, and a >>31).
It doesn't support 64 bits (due to integer-pointer casts, and `a >>31`).
It does work on 64-bit Linux, because all functions are below 4GB.
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC winner 2011/goren
#
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
# this way allows us to have the user specify a different compiler in an easy
# way.
if [[ -z "$CC" ]]; then
CC="cc"
fi
make CC="$CC" all >/dev/null || exit 1
# clear screen after compilation so that only the entry is shown
clear
read -r -n 1 -p "Press any key to run: echo 'Hello, world!' | ./goren: "
echo "Hello, world!" | ./goren
echo 1>&2
read -r -n 1 -p "Press any key to run: echo '|' | ./goren: "
echo '|' | ./goren
echo 1>&2
read -r -n 1 -p "Press any key to run: echo '|!|!|' | ./goren: "
echo '|' | ./goren
echo 1>&2
read -r -n 1 -p "Press any key to run: echo 'This is a pipe!' | ./goren: "
echo 'This is a pipe!' | ./goren
echo 1>&2
read -r -n 1 -p "Press any key to run: echo '| is a pipe!' | ./goren: "
echo '| is a pipe!' | ./goren
echo 1>&2
+3 -1
View File
@@ -3224,7 +3224,9 @@ for 64-bit so it was then tested as a 32-bit binary (linux) and 64-bit binary
(linux, macOS) and both work. It was fixed by changing some `int`s to `long`s
and now it does work with 64-bit systems as well as 32-bit systems.
Cody added the following words of wisdom: 'this is not a pipe'.
Cody also added the [try.sh](2011/goren/try.sh) script.
Cody added the following words of wisdom: '"this" is not a pipe but "!" is'.
## [2011/hou](2011/hou/hou.c) ([README.md](2011/hou/README.md]))