Files
ioccc/2015/burton/index.html
T

375 lines
22 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- START: two lines up starts content from: inc/top.default.html -->
<!-- -->
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
<!-- !!! DO NOT MODIFY THIS FILE - This file is generated by a tool !!! -->
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<!-- -->
<!-- END: this line ends content from: inc/top.default.html -->
<!-- -->
<!-- This web page was formed via the tool: bin/readme2index.sh -->
<!-- -->
<!-- The content of main section of this web page came from: 2015/burton/README.md -->
<!-- -->
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<!-- !!! Do not modify this web page, instead modify the file: 2015/burton/README.md -->
<!-- !!! Do not modify this web page, instead modify the file: 2015/burton/README.md -->
<!-- !!! Do not modify this web page, instead modify the file: 2015/burton/README.md -->
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<!-- -->
<!-- Markdown content was converted into HTML via the tool: bin/md2html.sh -->
<!-- -->
<!-- START: this line starts content from: inc/head.default.html -->
<head>
<link rel="stylesheet" href="../../ioccc.css">
<link rel=“shortcut icon” HREF=“"../../ioccc.ico”>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>2015/burton - Most Useful</title>
<meta name="description" content="2015 IOCCC entry burton - Most Useful">
<meta name="keywords" content="IOCCC, 2015, IOCCC 2015, IOCCC entry, burton, Most Useful">
</head>
<!-- END: this line ends content from: inc/head.default.html -->
<!-- START: this line starts content from: inc/body.default.html -->
<body>
<!-- END: this line ends content from: inc/body.default.html -->
<!-- START: this line starts content from: inc/header.default.html -->
<div class="header">
<img src="../../png/ioccc.png" alt="IOCCC image by Matt Zucker" width=300 height=110>
<h1>The International Obfuscated C Code Contest</h1>
<h2>2015/burton - Most Useful</h2>
</div>
<!-- END: this line ends content from: inc/header.default.html -->
<!-- START: this line starts content from: inc/topnav.first.html -->
<div class="topnav">
<a class="Left Disabled" href="#">first entry</a>
<a class="Left" href="../index.html">&uarr; 2015 &uarr;</a>
<a class="Left" href="../dogon/index.html">dogon &rarr;</a>
<a class="Right" href="https://github.com/ioccc-src/temp-test-ioccc/2015/burton/prog.c">C code</a>
<a class="Right" href="https://github.com/ioccc-src/temp-test-ioccc/2015/burton/Makefile">Makefile</a>
<a class="Right" href="#inventory">Inventory</a>
</div>
<!-- END: this line ends content from: inc/topnav.first.html -->
<!-- START: this line starts content from: inc/begin-row.default.html -->
<div class="row">
<!-- END: this line ends content from: inc/begin-row.default.html -->
<!-- START: this line starts content from: inc/begin-leftcolumn.default.html -->
<div class="leftcolumn">
<!-- END: this line ends content from: inc/begin-leftcolumn.default.html -->
<!-- START: this line starts content from: inc/sidenav.default.html -->
<div class="sidenav">
<a href="#content">Jump to contents</a>
</div>
<hr>
<div class="sidenav">
<a href="../../index.html">IOCCC Home</a>
<a href="../../years.html">Winning Entries</a>
<a href="../../authors.html">People who have won</a>
<a href="../../location.html">Location of authors</a>
</div>
<hr>
<div class="sidenav">
<a href="../../news.html">IOCCC News</a>
<a href="../../status.html">Contest status</a>
<a href="../../faq.html#submit">How to enter the IOCCC</a>
<a href="../../faq.html">FAQ</a>
</div>
<hr>
<div class="sidenav">
<a href="../../bugs.html">Bugs &amp; (mis)features</a>
<a href="../../faq.html#fix_an_entry">Fixing IOCCC entries</a>
<a href="../../faq.html#fix_web_site">Fixing the web site</a>
<a href="../../faq.html#fix_author">Fixing author info</a>
<a href="../../thanks-for-help.html">Thanks for the help</a>
</div>
<hr>
<div class="sidenav">
<a href="../../judges.html">The IOCCC Judges</a>
<a href="../../contact.html">Contacting the IOCCC</a>
</div>
<hr>
<div class="sidenav">
<a href="#top">Jump to top</a>
</div>
<!-- END: this line ends content from: inc/sidenav.default.html -->
<!-- START: this line starts content from: inc/end-leftcolumn.default.html -->
</div>
<!-- END: this line ends content from: inc/end-leftcolumn.default.html -->
<!-- START: this line starts content from: inc/begin-rightcolumn.default.html -->
<div class="rightcolumn">
<!-- END: this line ends content from: inc/begin-rightcolumn.default.html -->
<!-- START: this line starts content from: inc/before-content.default.html -->
<a name="content"></a>
<!-- END: this line ends content from: inc/before-content.default.html -->
<!-- START: this line starts content for HTML phase 20 by: bin/output-index-author.sh via bin/md2html.sh -->
<!-- START: this line starts content generated by: bin/output-index-author.sh -->
<h2 id="author"><a name="author"></a>Author:</h2>
<ul>
<li>Name: <a href="../../authors.html#Dave_Burton">Dave Burton</a><br>
Location: <a href="../../location.html#US">US</a> - <em>United States of America</em> (<em>United States</em>)
<br><br></li>
</ul>
<!-- END: next line ends content generated by: bin/output-index-author.sh -->
<!-- END: this line ends content for HTML phase 20 by: bin/output-index-author.sh via bin/md2html.sh -->
<!-- START: this line starts content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<h2 id="to-build">To build:</h2>
<div class="sourceCode" id="cb1"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="fu">make</span></span></code></pre></div>
<h2 id="to-use">To use:</h2>
<div class="sourceCode" id="cb2"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./prog</span> <span class="st">&quot;expression&quot;</span></span></code></pre></div>
<p>or:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./prog</span></span></code></pre></div>
<p>Type in expressions on standard input.</p>
<h2 id="try">Try:</h2>
<div class="sourceCode" id="cb4"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./try.sh</span></span></code></pre></div>
<p>Notice how the script reads in from a file. If you type just:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./prog</span></span></code></pre></div>
<p>it will prompt you in the same way. Send ctrl-c to exit.</p>
<p>Finally, if you wish to read the man page:</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">man</span> ./calc.1</span></code></pre></div>
<h2 id="alternate-code">Alternate code:</h2>
<p>An alternate version of this entry, <a href="prog.alt.c">prog.alt.c</a>, is provided.
This alternate code is discussed in the “prog.c vs prog.alt.c” section of the
author’s remarks below.</p>
<h3 id="alternate-build">Alternate build:</h3>
<div class="sourceCode" id="cb7"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="fu">make</span> alt</span></code></pre></div>
<h3 id="alternate-use">Alternate use:</h3>
<p>Use <code>prog.alt</code> as you would <code>prog</code> above.</p>
<h2 id="judges-remarks">Judges’ remarks:</h2>
<p>“Look, Ma, no <del>hands</del> digits!”</p>
<p>The place where some arithmetic operations are done, for example, division or
modulo, are easy to find. Where are addition and subtraction?</p>
<p>We were impressed with the level of detail the author “blogged” the obfuscation
process.</p>
<h2 id="authors-remarks">Author’s remarks:</h2>
<h3 id="calc---an-integer-expression-calculator-that-outputs-in-both-hex-and-decimal">calc - an integer expression calculator that outputs in both hex and decimal</h3>
<p>All useful tools should include sufficient documentation.
See the included man page. ;-)</p>
<h3 id="notes">Notes</h3>
<p>This program is named <code>calc</code>. Onomatopoeia of sorts, in the visual realm. The
formatting was easier: Form Follows Function (although <a href="../../2011/hou/hint.html" title="Hou Qiming">Hou</a> did this
better). It was tempting to call it iCalc, with <code>i</code> for integer (and it was
written on an <code>iDevice</code>), but sanity prevailed.</p>
<p>Printed in 8 pt Courier, it makes aesthetically pleasing 8.5 x 11 wall art.</p>
<h3 id="prog.c-vs-prog.alt.c">prog.c vs prog.alt.c</h3>
<p><a href="../../authors.html#Dominik_Muth">Dominik Muth</a> observed a syntax error on <code>1+1</code>,
<code>1-1</code>, <code>1|1</code>, and <code>1^1</code> when using an ARM based computer, although <code>1*1</code> and
others worked correctly. This occurs because some platforms by default treat
<code>char</code> as <code>unsigned char</code>. The original code has this weakness, which can be
corrected by adding <code>-fsigned-char</code> to the compile line.</p>
<p>The modified code is agnostic to <code>char</code> signedness.</p>
<h3 id="why-is-this-entry-obfuscatedinteresting">Why is this entry obfuscated/interesting?</h3>
<p>Yes, this is another calculator program.</p>
<p>However, unlike any other calculator source code the author is aware of,
this one contains no digits. At all. Anywhere. As in</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">grep</span> <span class="st">&#39;[0-9]&#39;</span> prog.c <span class="kw">||</span> <span class="bu">echo</span> no digits!</span></code></pre></div>
<p>Nor are the digits simply obfuscated. There are no character constants. There
is only one single, short string, and it does not contain any obfuscated digits.
And yet the output is in decimal and hexadecimal, and it accepts octal, decimal,
and hex input.</p>
<p>Flow control is by <code>for</code> and <code>return</code>. It is <code>if</code>-less, <code>switch</code>-less,
<code>while</code>-less, and hopeless. Literally, if not figuratively. ;-)</p>
<p>The code size is intentionally 2015, as stated by <code>iocccsize -i</code>, and can be
reformatted without changes (as in <a href="rule2.c">rule2.c</a>) to exactly 4096 octets.</p>
<p>Finally, <code>calc</code> is interesting, if for no other reason than it is practically
useful: Hex/decimal conversion, arithmetic, byte-swapping, bit-shifting, and
logical operations with memory, on the command line, or interactively.</p>
<h3 id="but-the-question-is-why-is-the-entry-obfuscated">But the question is why is the entry obfuscated?</h3>
<p>The code follows many industry best-practices:</p>
<ul>
<li><p>You know what it does just by looking at it.</p></li>
<li><p>Numbers and digits have often been used for obfuscation,
so in a bid for better clarity, this code has no digits at all.</p></li>
<li><p>In the spirit of clarity, most of the variables are declared before use, so
they are readily visible, with single letter names that don’t clutter the
screen, in a tautological arrangement.</p></li>
<li><p>More helpful is the use of <code>typedef</code>s instead of <code>#define</code>, so the types
remain useful even in the debugger, and source code beautifiers will not undo
careful presentation.</p></li>
<li><p><code>#defines</code> are used here in the best spirit of the preprocessor: to shorten
repetitive constructs, not for obscurity.</p></li>
<li><p>All functions are short (and therefore easy to understand?) and do only one
thing, well, ….</p></li>
<li><p>Curly braces invite endless holy wars over readability. This code only uses
them for function definitions, thereby greatly improving readability, and
reducing arguments about said readability.</p></li>
<li><p>One of C’s many blessings (until recently) is a modicum of keywords, of which
only 8 are used: <code>for</code>, <code>return</code>, <code>typedef</code>, <code>void</code>, <code>char</code>, <code>short</code>, <code>unsigned</code>
and <code>long</code>; 10 if <code>#include</code> and <code>#define</code> are counted.</p></li>
<li><p>The code helpfully declares <code>"syntax_error!"</code> right up front, filling the
reader with confidence.</p></li>
<li><p>In spite of its inherent clarity, the code was presented to both <code>indent(1)</code>
and <code>clang-format(1)</code>, after running it through the preprocessor, sustaining its
better qualities.</p></li>
<li><p>That the code is obfuscated is spelled out two different ways in the source;
it helps to reformat the code to see the second spelling.</p></li>
<li><p>The author is overly fond of the code that handles input. There is no memory
allocation, nor pre-allocation of arrays, so where does the memory come from?
The multi-base <code>strtol(3)</code> code is pretty tricky. No special attempt was made to
replace operations with obscure mathematical relations, as the (lack of) beauty
is in the parsing – ask not where is the modulus operation, but how does it
know when to mod – okay, but where is add and subtract? And really, who
doesn’t enjoy a <code>setjmp(3)</code> in the argument list?</p></li>
<li><p>Finally, documentation of the source code structure is helpfully provided in
rot13 format. But isn’t it unsportsmanlike to rely upon it? However, even with
this helpful guide, things like reading input lines remain as tricky to read as
they are to write.</p></li>
</ul>
<h3 id="compiler-warnings">Compiler warnings</h3>
<p><code>calc</code> is C99 compliant, and is ANSI/C90 compliant except for wanting 64-bit <code>long long</code>. Changing the two <code>long long</code> typedefs to <code>long</code>, and compiling with <code>gcc -m32</code> yields a program that operates on 32-bit values, with wrap-around of
shifts mod 32:</p>
<pre><code>1&lt;&lt;48
65536 0x00010000</code></pre>
<p>gcc 4.2.1 without arguments compiles cleanly (e.g. <code>cc prog.c -o prog</code>).
This is my workaday compiler. gcc is also clean with <code>-ansi</code>, and <code>-std=c99</code>.</p>
<p>clang 3.6.0 lives up to its namesake, resounding on non-problems.
To stifle these complaints:</p>
<pre><code>-Wno-return-type -Wno-parentheses -Wno-empty-body</code></pre>
<p>When invoked with <code>-ansi -pedantic</code>, there are two warnings, which can be ignored:</p>
<ul>
<li><code>ISO C90 does not support 'long long'</code></li>
</ul>
<p>With <code>-Wall -std=c99</code>, both are quite noisy, and all can be ignored:</p>
<ul>
<li><code>array subscript has type 'char' [-Wchar-subscripts]</code></li>
<li><code>value computed is not used [-Wunused-value]</code></li>
<li><code>operation on 'j' may be undefined [-Wsequence-point]</code></li>
</ul>
<h3 id="test-suite">Test Suite:</h3>
<p>If the program name begins with an <code>e</code>, it echoes <code>stdin</code> to <code>stdout</code>.
This allows for a convenient test suite:</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">ln</span> <span class="at">-sf</span> prog eprog</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="va">PATH</span><span class="op">=</span>. <span class="ex">eprog</span> <span class="op">&lt;</span> test.in <span class="kw">|</span> <span class="fu">diff</span> <span class="at">-</span> test.out</span></code></pre></div>
<h3 id="spoilers">Spoilers:</h3>
<p>If you do not want to puzzle out how it works, see <a href="spoilers.html">spoilers.html</a>.</p>
<!--
Copyright © 1984-2024 by Landon Curt Noll. All Rights Reserved.
You are free to share and adapt this file under the terms of this license:
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
For more information, see:
https://creativecommons.org/licenses/by-sa/4.0/
-->
<!-- END: this line ends content for HTML phase 21 by: bin/pandoc-wrapper.sh via bin/md2html.sh -->
<!-- START: this line starts content for HTML phase 22 by: bin/output-index-inventory.sh via bin/md2html.sh -->
<!-- START: this line starts content generated by: bin/output-index-inventory.sh -->
<h1 id="inventory-for-2015burton"><a name="inventory"></a>Inventory for 2015/burton</h1>
<p><a href="#top">Jump to top</a></p>
<h2 id="primary-files">Primary files</h2>
<ul>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/prog.c">prog.c</a> - entry source</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/Makefile">Makefile</a> - entry Makefile</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/prog.alt.c">prog.alt.c</a> - alternative source</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/prog.orig.c">prog.orig.c</a> - original source</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/try.sh">try.sh</a> - how to run</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/try.this.txt">try.this.txt</a> - try.sh input</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/calc.1">calc.1</a> - man page for integer expression calculator</li>
<li><a href="road.to.obscurity.html">road.to.obscurity.html</a> - obfuscated calculator development notes</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/rule2.c">rule2.c</a> - iocccsize reformatted to exactly 4096 octets</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/test32.out">test32.out</a> - test suite comparison data for 32-bit systems</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/test.in">test.in</a> - test suite input data</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/test.out">test.out</a> - test suite comparison data</li>
<li><a href="spoilers.html">spoilers.html</a> - SPOILER WARNING</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/src.doc.txt">src.doc.txt</a> - SPOILER WARNING hints about the source</li>
<li><a href="2015_burton.tar.bz2">2015_burton.tar.bz2</a> - download entry</li>
</ul>
<h2 id="secondary-files">Secondary files</h2>
<ul>
<li><a href="index.html">index.html</a> - entry home page</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/README.md">README.md</a> - markdown source for index.html</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/.entry.json">.entry.json</a> - description of entry in JSON</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/.gitignore">.gitignore</a> - list of files that should not be committed under git</li>
<li><a href=".path">.path</a> - directory path from top directory</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/road.to.obscurity.md">road.to.obscurity.md</a> - markdown source for road.to.obscurity.html</li>
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/burton/spoilers.md">spoilers.md</a> - markdown source for spoilers.html</li>
</ul>
<!-- END: next line ends content generated by: bin/output-index-inventory.sh -->
<!-- END: this line ends content for HTML phase 22 by: bin/output-index-inventory.sh via bin/md2html.sh -->
<!-- START: this line starts content from: inc/after-content.default.html -->
<!-- END: this line ends content from: inc/after-content.default.html -->
<!-- START: this line starts content from: inc/end-rightcolumn.default.html -->
</div>
<!-- END: this line ends content from: inc/end-rightcolumn.default.html -->
<!-- START: this line starts content from: inc/end-row.default.html -->
</div>
<!-- END: this line ends content from: inc/end-row.default.html -->
<!-- START: this line starts content from: inc/footer.default.html -->
<!--
Copyright © 1984-2024 by Landon Curt Noll. All Rights Reserved.
You are free to share and adapt this file under the terms of this license:
Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
For more information, see:
https://creativecommons.org/licenses/by-sa/4.0/
-->
<div class="footer">
<h2>Copyright and CC BY-SA 4.0 License</h2>
<p>This file and web page is:</p>
<blockquote><b>Copyright &copy; 1984-2024 by Landon Curt Noll. All Rights Reserved.</b></p></blockquote>
<p>You are free to share and adapt this file under the terms of this license:</p>
<blockquote><b>Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)</b></blockquote>
<p>For more information, see:</p>
<blockquote><a
href="https://creativecommons.org/licenses/by-sa/4.0/">https://creativecommons.org/licenses/by-sa/4.0/</a></blockquote>
<h2>Coda</h2>
<p><a href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fioccc-src.github.io%2Ftemp-test-ioccc%2F2015%2Fburton%2Findex.html">Nu HTML check this web page</a></p>
<p><a href="#top">Jump to top</a> <a href="#content">Jump to Content</a> <a href="#inventory">Jump to Inventory</a></p>
</div>
<!-- END: this line ends content from: inc/footer.default.html -->
<!-- START: this line starts content from: inc/bottom.default.html -->
</body>
</html>
<!-- END: this line ends content from: inc/bottom.default.html -->