Merge pull request #1568 from xexyl/goren2011
This commit is contained in:
4 files changed
+52
-12
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
+11
-11
@@ -15,7 +15,7 @@ echo "some text" | ./goren
|
|||||||
### Try:
|
### Try:
|
||||||
|
|
||||||
```sh
|
```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):
|
In the words of [René François Ghislain Magritte Magritte](http://en.wikipedia.org/wiki/Rene_Magritte):
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
One may ask the surrealist question:
|
One may ask the surrealist question:
|
||||||
|
|
||||||
@@ -65,31 +65,31 @@ stuffing data.
|
|||||||
|
|
||||||
One thing I tried to achieve is condition free programming. Many
|
One thing I tried to achieve is condition free programming. Many
|
||||||
have noted that conditions make the code harder to read and understand.
|
have noted that conditions make the code harder to read and understand.
|
||||||
A good example would be:
|
A good example would be: [Brent Burley's 2004 IOCCC
|
||||||
|
winner](/2004/burley/README.md).
|
||||||
[Brent Burley's 2004 IOCCC winner](/2004/burley/burley.c).
|
|
||||||
|
|
||||||
That entry omits conditional statements such as `if` and `while`.
|
That entry omits conditional statements such as `if` and `while`.
|
||||||
His achievement in improving clarity by omitting conditions is
|
His achievement in improving clarity by omitting conditions is
|
||||||
impressive, but I think it can be taken further, in two ways.
|
impressive, but I think it can be taken further, in two ways.
|
||||||
|
|
||||||
First, conditional operators, such as `?:`, `&&` and `||`, can be thrown
|
First, conditional operators, such as `?:`, `&&` and `||`, can be thrown away.
|
||||||
away. Second, using `setjmp` and `longjmp`, which are unfortunately
|
Second, using `setjmp(3)` and `longjmp(3)`, which are unfortunately not in
|
||||||
not in common use, might make it difficult for a novice programmer
|
common use, might make it difficult for a novice programmer to understand the
|
||||||
to understand the code without referring to the man page.
|
code without referring to the man page.
|
||||||
|
|
||||||
By removing these, the code is 100% condition free, and every
|
By removing these, the code is 100% condition free, and every
|
||||||
function runs its instructions in perfect order. Naturally, this
|
function runs its instructions in perfect order. Naturally, this
|
||||||
makes the program flow trivial to understand. This can be verified
|
makes the program flow trivial to understand. This can be verified
|
||||||
by disassembling the compiled code and looking for conditional jumps
|
by disassembling the compiled code and looking for conditional jumps
|
||||||
(when compiled with gcc on x86, there are none).
|
(when compiled with gcc on x86, there are none).
|
||||||
|
|
||||||
|
|
||||||
### Compatibility:
|
### Compatibility:
|
||||||
|
|
||||||
The program should compile with any C compiler, but was tested
|
The program should compile with any C compiler, but was tested
|
||||||
mostly with gcc on Linux.
|
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.
|
It does work on 64-bit Linux, because all functions are below 4GB.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Executable
+38
@@ -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
@@ -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
|
(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.
|
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]))
|
## [2011/hou](2011/hou/hou.c) ([README.md](2011/hou/README.md]))
|
||||||
|
|||||||
Reference in new issue
Block a user