force use of pandoc version >= 3.1.12.2
The `bin/pandoc-wrapper.sh` tool will verify that the ssytem has a recent enough version of `pandoc(1)`. We explain why we insist on `pandoc(1)`. version >= 3.1.12.2 in comments where the $PANDOC_MIN_VERSION is set. Added `--wrap=preserve` as a default argument to `pandoc(1)`. While this change will impact every HTML file generated, we believe this will improve the ability of someone to look at the generated HTML and correlate with the original markdown. Changed `bin/pandoc-wrapper.sh` VERSION from "1.4.2 2024-03-17" to "1.4.3 2024-03-18". Performed `make www` to achieve all of the above and to generate HTML using the new `--wrap=preserve` `pandoc(1)` mode.
This commit is contained in:
1 parent
9eb7a54e9f
commit
b0b212acb1
402 files changed
+37061
-55132
No files matched your search
+274
-383
@@ -129,9 +129,9 @@
|
||||
|
||||
<h2 id="author"><a name="author"></a>Author:</h2>
|
||||
<ul>
|
||||
<li>Name: <a href="../../authors.html#Jens_Schweikhardt">Jens
|
||||
Schweikhardt</a><br> Location: <a href="../../location.html#DE">DE</a> -
|
||||
<em>Federal Republic of Germany</em> (<em>Germany</em>) <br><br></li>
|
||||
<li>Name: <a href="../../authors.html#Jens_Schweikhardt">Jens Schweikhardt</a><br>
|
||||
Location: <a href="../../location.html#DE">DE</a> - <em>Federal Republic of Germany</em> (<em>Germany</em>)
|
||||
<br><br></li>
|
||||
</ul>
|
||||
|
||||
<!-- END: next line ends content generated by: bin/output-index-author.sh -->
|
||||
@@ -144,42 +144,36 @@ Schweikhardt</a><br> Location: <a href="../../location.html#DE">DE</a> -
|
||||
<h3 id="bugs-and-misfeatures">Bugs and (Mis)features:</h3>
|
||||
<p>The current status of this entry is:</p>
|
||||
<pre><code>STATUS: INABIAF - please **DO NOT** fix</code></pre>
|
||||
<p>For more detailed information see <a
|
||||
href="../../bugs.html#2015_schweikhardt">2015 schweikhardt bugs</a>.</p>
|
||||
<p>For more detailed information see <a href="../../bugs.html#2015_schweikhardt">2015 schweikhardt bugs</a>.</p>
|
||||
<h2 id="to-use">To use:</h2>
|
||||
<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> n</span></code></pre></div>
|
||||
<p>where n is a base 16 number of any size.</p>
|
||||
<p>NOTE: although it’s supposed to be a base 16 number nothing will stop
|
||||
you from doing something else. The author explains this in more
|
||||
details.</p>
|
||||
<p>NOTE: although it’s supposed to be a base 16 number nothing will stop you from
|
||||
doing something else. The author explains this in more details.</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>After running it once to see what commands are run, you might wish to
|
||||
run it a second time and just hold down space to see a fun scroll of
|
||||
numbers especially where zeroes move to the right.</p>
|
||||
<p>After running it once to see what commands are run, you might wish to run it a
|
||||
second time and just hold down space to see a fun scroll of numbers especially
|
||||
where zeroes move to the right.</p>
|
||||
<h2 id="judges-remarks">Judges’ remarks:</h2>
|
||||
<p>This code is clean. When you compile with all warnings enabled, such
|
||||
as with clang:</p>
|
||||
<p>This code is clean. When you compile with all warnings enabled,
|
||||
such as with clang:</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="fu">cc</span> <span class="at">-Weverything</span> <span class="at">-pedantic</span> <span class="at">-std</span><span class="op">=</span>c11 <span class="at">-Dtyp</span><span class="op">=</span>uint64<span class="dt">\_</span>t <span class="at">-O3</span> prog.c <span class="at">-o</span> prog</span></code></pre></div>
|
||||
<p>The code compiles without warnings on the systems that we tested!</p>
|
||||
<p>Even more, the code was 100% clean when we ran it against various
|
||||
static source checkers.</p>
|
||||
<p>This tool references a problem that <a
|
||||
href="http://members.tip.net.au/~dbell/">David I. Bell</a> once
|
||||
described as having one of the largest “yummo quotients” in number
|
||||
theory:</p>
|
||||
<p>This tool references a problem that <a href="http://members.tip.net.au/~dbell/">David I.
|
||||
Bell</a> once described
|
||||
as having one of the largest “yummo quotients” in number theory:</p>
|
||||
<pre><code> complexity of the solution
|
||||
yummo quotient = -----------------------------------
|
||||
complexity of the problem statement</code></pre>
|
||||
<p><a href="https://en.wikipedia.org/wiki/Paul_Erdős">Erdős</a>
|
||||
privately told one of the IOCCC judges:</p>
|
||||
<p><a href="https://en.wikipedia.org/wiki/Paul_Erdős">Erdős</a> privately told one of the IOCCC judges:</p>
|
||||
<blockquote>
|
||||
<p>Solving the <a
|
||||
href="https://en.wikipedia.org/wiki/Generalized_Riemann_hypothesis#Extended_Riemann_hypothesis_.28ERH.29">Generalized
|
||||
Riemann hypothesis</a> would be a good warm-up exercise for someone to
|
||||
get ready to begin to work on the <a
|
||||
href="https://en.wikipedia.org/wiki/Collatz_conjecture">Collatz
|
||||
conjecture</a>.</p>
|
||||
<p>Solving the <a href="https://en.wikipedia.org/wiki/Generalized_Riemann_hypothesis#Extended_Riemann_hypothesis_.28ERH.29">Generalized Riemann
|
||||
hypothesis</a>
|
||||
would be a good warm-up exercise for someone to get ready to begin to work on
|
||||
the <a href="https://en.wikipedia.org/wiki/Collatz_conjecture">Collatz conjecture</a>.</p>
|
||||
</blockquote>
|
||||
<p>You may explore this famous conjecture using this entry:</p>
|
||||
<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="ex">./prog</span> 2410</span>
|
||||
@@ -191,37 +185,34 @@ conjecture</a>.</p>
|
||||
<span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a><span class="ex">./prog</span> 1b7dd73a937485bf</span>
|
||||
<span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a><span class="ex">./prog</span> 7d3237680d190a77e53751b</span>
|
||||
<span id="cb7-9"><a href="#cb7-9" aria-hidden="true" tabindex="-1"></a><span class="ex">./prog</span> 302ab3d052fb87c06228d249581be0e4</span></code></pre></div>
|
||||
<p>NOTE: <a href="try.sh">try.sh</a> runs these for you, filtered
|
||||
through <code>less(1)</code>.</p>
|
||||
<p>When you first look at the source, the code looks fairly
|
||||
straightforward. But look again. Like the Collatz conjecture, simplicity
|
||||
is deceptive! Oh, and the variable names? They are not simple single
|
||||
letter variables, they are names of various <a
|
||||
href="https://en.wikipedia.org/wiki/Proteinogenic_amino_acid">Proteinogenic
|
||||
amino acid</a>: which is yet another simple building block that can be
|
||||
used to build some very complex structures. :-)</p>
|
||||
<p>NOTE: <a href="try.sh">try.sh</a> runs these for you, filtered through <code>less(1)</code>.</p>
|
||||
<p>When you first look at the source, the code looks fairly straightforward.
|
||||
But look again. Like the Collatz conjecture, simplicity is deceptive!
|
||||
Oh, and the variable names? They are not simple single letter variables,
|
||||
they are names of various <a href="https://en.wikipedia.org/wiki/Proteinogenic_amino_acid">Proteinogenic amino
|
||||
acid</a>:
|
||||
which is yet another simple building block that can be used to
|
||||
build some very complex structures. :-)</p>
|
||||
<p>p.s. We appreciated that apart from a few powers of 2, the source
|
||||
code is magic number free.</p>
|
||||
<h2 id="authors-remarks">Author’s remarks:</h2>
|
||||
<h3 id="the-tldr-version">The TL;DR version</h3>
|
||||
<p>This is the cleanest program ever submitted. If for some input it
|
||||
enters a non-terminating loop or runs out of memory you will be
|
||||
insta-famous. It’s a bit like a lottery without the need to buy a ticket
|
||||
and you can play as often as you like. One notable historic person has
|
||||
even offered some prize money.</p>
|
||||
<p>The program illustrates the bloat caused by adherence to too many
|
||||
rules, each of which may sound sane in isolation, but in their entirety
|
||||
lead to an obfuscated, hard to read and understand monster.</p>
|
||||
<p>This is the cleanest program ever submitted. If for some input it enters
|
||||
a non-terminating loop or runs out of memory you will be insta-famous.
|
||||
It’s a bit like a lottery without the need to buy a ticket and you can
|
||||
play as often as you like. One notable historic person has even offered
|
||||
some prize money.</p>
|
||||
<p>The program illustrates the bloat caused by adherence to too many rules,
|
||||
each of which may sound sane in isolation, but in their entirety lead to
|
||||
an obfuscated, hard to read and understand monster.</p>
|
||||
<h3 id="what-this-program-does.">What this program does.</h3>
|
||||
<p>The program tests whether a given natural number satisfies the <a
|
||||
href="https://en.wikipedia.org/wiki/Collatz_conjecture">Collatz
|
||||
Conjecture</a>:</p>
|
||||
<p>Take any natural number <code>n</code>. If <code>n</code> is even,
|
||||
divide it by <code>2</code> to get <code>n/2</code>. If <code>n</code>
|
||||
is odd, multiply it by <code>3</code> and add <code>1</code> to obtain
|
||||
<code>3n + 1</code>. Repeat the process indefinitely.</p>
|
||||
<p>The conjecture is that no matter what number you start with, you
|
||||
eventually reach <code>1</code>.</p>
|
||||
<p>The program tests whether a given natural number satisfies the
|
||||
<a href="https://en.wikipedia.org/wiki/Collatz_conjecture">Collatz Conjecture</a>:</p>
|
||||
<p>Take any natural number <code>n</code>. If <code>n</code> is even, divide it by <code>2</code> to get <code>n/2</code>. If
|
||||
<code>n</code> is odd, multiply it by <code>3</code> and add <code>1</code> to obtain <code>3n + 1</code>. Repeat the
|
||||
process indefinitely.</p>
|
||||
<p>The conjecture is that no matter what number you start with,
|
||||
you eventually reach <code>1</code>.</p>
|
||||
<p>Paul Erdős said about the Collatz conjecture:</p>
|
||||
<blockquote>
|
||||
<p>“Mathematics may not be ready for such problems.”</p>
|
||||
@@ -231,9 +222,9 @@ eventually reach <code>1</code>.</p>
|
||||
<blockquote>
|
||||
<p>6, 3, 10, 5, 16, 8, 4, 2, 1.</p>
|
||||
</blockquote>
|
||||
<p>Continuing past one leads to the <em>cycle</em> 1, 4, 2, 1, 4, 2, 1,
|
||||
… Interesting factoid: if you allow <em>negative</em> start values,
|
||||
there are a few more cycles, each of different length:</p>
|
||||
<p>Continuing past one leads to the <em>cycle</em> 1, 4, 2, 1, 4, 2, 1, …
|
||||
Interesting factoid: if you allow <em>negative</em> start values, there are
|
||||
a few more cycles, each of different length:</p>
|
||||
<pre><code>−1, −2, −1
|
||||
|
||||
−5, −14, −7, −20, −10, −5
|
||||
@@ -242,11 +233,10 @@ there are a few more cycles, each of different length:</p>
|
||||
−82, −41, −122, −61, −182, −91, −272, −136,
|
||||
−68, −34, −17</code></pre>
|
||||
<p>The program computes the sequence for a given positive natural number
|
||||
and stops at <code>1</code>. The number <code>n</code> is specified in
|
||||
hexadecimal (without <code>0x</code> prefix) as the first argument. The
|
||||
program prints the given number in zero-padded hex and each iteration
|
||||
along with a line count in decimal. The example above looks like this
|
||||
(compiled with 64 bit word size):</p>
|
||||
and stops at <code>1</code>. The number <code>n</code> is specified in hexadecimal (without <code>0x</code>
|
||||
prefix) as the first argument. The program prints the given number in
|
||||
zero-padded hex and each iteration along with a line count in decimal.
|
||||
The example above looks like this (compiled with 64 bit word size):</p>
|
||||
<div class="sourceCode" id="cb9"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> ./prog 6</span>
|
||||
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="ex">0000000000000006</span></span>
|
||||
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a><span class="ex">0000000000000003</span> 1</span>
|
||||
@@ -257,87 +247,78 @@ along with a line count in decimal. The example above looks like this
|
||||
<span id="cb9-8"><a href="#cb9-8" aria-hidden="true" tabindex="-1"></a><span class="ex">0000000000000004</span> 6</span>
|
||||
<span id="cb9-9"><a href="#cb9-9" aria-hidden="true" tabindex="-1"></a><span class="ex">0000000000000002</span> 7</span>
|
||||
<span id="cb9-10"><a href="#cb9-10" aria-hidden="true" tabindex="-1"></a><span class="ex">0000000000000001</span> 8</span></code></pre></div>
|
||||
<p>The size of <code>n</code> is only limited by the argument size limit
|
||||
of your shell/OS (the program implements arbitrary size
|
||||
<code>bignum</code>s). To query this on your POSIX system, run</p>
|
||||
<div class="sourceCode" id="cb10"><pre
|
||||
class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> getconf ARG_MAX</span>
|
||||
<p>The size of <code>n</code> is only limited by the argument size limit of your
|
||||
shell/OS (the program implements arbitrary size <code>bignum</code>s).
|
||||
To query this on your POSIX system, run</p>
|
||||
<div class="sourceCode" id="cb10"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> getconf ARG_MAX</span>
|
||||
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a><span class="ex">262144</span></span></code></pre></div>
|
||||
<p>which reports the limit in bytes, here 256KB. This allows to test
|
||||
whether a <a href="https://en.wikipedia.org/wiki/Googol">Googol</a>,
|
||||
which is 10<sup>100</sup>, satisfies the conjecture. But what is a
|
||||
googol in hex? Fear not, <a
|
||||
href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html">bc(1)</a>
|
||||
whether a <a href="https://en.wikipedia.org/wiki/Googol">Googol</a>, which is
|
||||
10<sup>100</sup>, satisfies the conjecture. But what is a googol in hex?
|
||||
Fear not,
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html">bc(1)</a>
|
||||
to the rescue:</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="ex">$</span> printf <span class="st">'obase=16;10^100\n'</span> <span class="kw">|</span> <span class="fu">bc</span></span>
|
||||
<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="ex">$</span> printf <span class="st">'obase=16;10^100\n'</span> <span class="kw">|</span> <span class="fu">bc</span></span>
|
||||
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="ex">1249AD2594C37CEB0B2784C4CE0BF38ACE408E211A7CAAB24308A82E8F1000000000</span><span class="dt">\</span></span>
|
||||
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="ex">0000000000000000</span></span>
|
||||
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> ./prog 1249AD2594C37CEB0B2784C4CE0BF38ACE408E211A7CAAB24308A82E8F10000000000000000000000000 <span class="dt">\</span></span>
|
||||
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a><span class="kw">|</span> <span class="fu">less</span></span>
|
||||
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a><span class="ex">[...]</span></span></code></pre></div>
|
||||
<p>Observe how the first 100 iterations melt the zeros to the right. Can
|
||||
you explain why?</p>
|
||||
<p>For a given <code>n</code> the program behavior is one of the
|
||||
following 3:</p>
|
||||
<p>Observe how the first 100 iterations melt the zeros to the right. Can you explain
|
||||
why?</p>
|
||||
<p>For a given <code>n</code> the program behavior is one of the following 3:</p>
|
||||
<ol type="1">
|
||||
<li>The sequence stops at 1. No fame. No money. Thanks for playing.
|
||||
Computational mathematicians have tested all
|
||||
<code>n < 4FFDD776055A0000</code> (~10<sup>18</sup>) so don’t try
|
||||
anything less than that.</li>
|
||||
<li>The chosen <code>n</code> leads to a sequence with ever bigger
|
||||
numbers, so that eventually the <code>bignum</code> cannot be stored in
|
||||
memory. If this happens, the program outputs <code>laugh</code> (more
|
||||
likely) or <code>throw up</code> (less likely) and stops. You
|
||||
<em>might</em> have found a number for which the sequence
|
||||
<em>diverges</em>. If confirmed, this disproves the conjecture.</li>
|
||||
<li>The chosen <code>n</code> leads to a cycle not including 1
|
||||
(i.e. runs forever, repeating the same sequence over and over). You have
|
||||
disproved the conjecture and should certainly submit a paper to the
|
||||
nearest mathematical journal.</li>
|
||||
<li>The sequence stops at 1. No fame. No money. Thanks for playing. Computational
|
||||
mathematicians have tested all <code>n < 4FFDD776055A0000</code> (~10<sup>18</sup>) so
|
||||
don’t try anything less than that.</li>
|
||||
<li>The chosen <code>n</code> leads to a sequence with ever bigger numbers, so that
|
||||
eventually the <code>bignum</code> cannot be stored in memory. If this happens, the program
|
||||
outputs <code>laugh</code> (more likely) or <code>throw up</code> (less likely) and stops. You <em>might</em>
|
||||
have found a number for which the sequence <em>diverges</em>. If confirmed, this
|
||||
disproves the conjecture.</li>
|
||||
<li>The chosen <code>n</code> leads to a cycle not including 1 (i.e. runs forever, repeating
|
||||
the same sequence over and over). You have disproved the conjecture and should
|
||||
certainly submit a paper to the nearest mathematical journal.</li>
|
||||
</ol>
|
||||
<h3 id="design-objectives">Design objectives</h3>
|
||||
<p>I gave myself the following objectives. Like in real world
|
||||
programming, not all of them can be met 100%. Think of them as a
|
||||
multidimensional continuum, where trade-offs have to be made.</p>
|
||||
<p>I gave myself the following objectives. Like in real world programming,
|
||||
not all of them can be met 100%. Think of them as a multidimensional
|
||||
continuum, where trade-offs have to be made.</p>
|
||||
<ol type="1">
|
||||
<li>No arbitrary limits on the input number. 64 bits might be enough for
|
||||
everybody, but is not enough for exploring new Collatz-territory. Thus
|
||||
<code>bignums</code> are required.</li>
|
||||
<li>Ultra-portable. Must run on C89 systems and self-adapt to C99 and
|
||||
C11 features like exact width types.</li>
|
||||
<li>No arbitrary limits on the input number. 64 bits might be enough
|
||||
for everybody, but is not enough for exploring new Collatz-territory.
|
||||
Thus <code>bignums</code> are required.</li>
|
||||
<li>Ultra-portable. Must run on C89 systems and self-adapt to C99 and C11
|
||||
features like exact width types.</li>
|
||||
<li>Super-efficient. Must be able to run with the widest type as the
|
||||
base of the <code>bignums</code>. Make the user select the widest type
|
||||
supported by the implementation and then crunch away. If a non-standard
|
||||
base of the <code>bignums</code>. Make the user select the widest type supported
|
||||
by the implementation and then crunch away. If a non-standard
|
||||
128bit type is available, it should be usable.</li>
|
||||
<li>Pentagon level lint cleanliness and MISRA compliance.</li>
|
||||
<li>Easy to understand, self-documenting clear code. A joy for
|
||||
maintenance programmers. The epitome of best practice demonstration for
|
||||
all future textbooks on C.</li>
|
||||
<li>Easy to understand, self-documenting clear code. A joy for maintenance
|
||||
programmers. The epitome of best practice demonstration for all
|
||||
future textbooks on C.</li>
|
||||
</ol>
|
||||
<h3 id="program-obfuscation">Program Obfuscation</h3>
|
||||
<p>In the following I address all the <em>tests</em> as specified by
|
||||
your honors in the <em>guidelines</em>.</p>
|
||||
<p>In the following I address all the <em>tests</em> as specified by your honors in the
|
||||
<em>guidelines</em>.</p>
|
||||
<ul>
|
||||
<li>look at the original source</li>
|
||||
<li>convert ANSI trigraphs to ASCII</li>
|
||||
<li>C pre-process the source ignoring <code>#include</code> lines</li>
|
||||
<li>C pre-process the source ignoring <code>#define</code> and
|
||||
<code>#include</code> lines</li>
|
||||
<li>C pre-process the source ignoring <code>#define</code> and <code>#include</code> lines</li>
|
||||
<li>run it through a C beautifier</li>
|
||||
<li>examine the algorithm</li>
|
||||
<li>compile it (with flags to enable all warnings)</li>
|
||||
<li>execute it</li>
|
||||
</ul>
|
||||
<h3 id="look-at-the-original-source">Look at the original source</h3>
|
||||
<p>Using one letter identifiers is quite old. I decided to use TLI
|
||||
(three letter identifiers). Not the random kind, rather with a
|
||||
connection to the meaning of life, the universe and the rest. Enter
|
||||
amino acids! Among the myriad of possible amino acids there are 23 from
|
||||
which proteins are built. In biochemistry, each is assigned a TLI (see
|
||||
<a
|
||||
href="https://en.wikipedia.org/wiki/Proteinogenic_amino_acid">Proteinogenic
|
||||
amino acid</a>):</p>
|
||||
<p>Using one letter identifiers is quite old. I decided to use TLI (three
|
||||
letter identifiers). Not the random kind, rather with a connection to
|
||||
the meaning of life, the universe and the rest. Enter amino acids! Among
|
||||
the myriad of possible amino acids there are 23 from which proteins are
|
||||
built. In biochemistry, each is assigned a TLI (see <a href="https://en.wikipedia.org/wiki/Proteinogenic_amino_acid">Proteinogenic amino
|
||||
acid</a>):</p>
|
||||
<pre><code> ala Alanine
|
||||
cys Cysteine
|
||||
asp Aspartic acid
|
||||
@@ -364,50 +345,34 @@ amino acid</a>):</p>
|
||||
glx Glutamic acid or Glutamine
|
||||
xle Leucine or Isoleucine
|
||||
unk Unknown</code></pre>
|
||||
<p>My own research results complete this list (not yet in Wikipedia due
|
||||
to the rule “<a
|
||||
href="https://en.wikipedia.org/wiki/Wikipedia:No_original_research">No
|
||||
original research</a>”):</p>
|
||||
<p>My own research results complete this list (not yet in Wikipedia due to
|
||||
the rule “<a href="https://en.wikipedia.org/wiki/Wikipedia:No_original_research">No original
|
||||
research</a>”):</p>
|
||||
<pre><code>and Androgynine
|
||||
xor Xenoricine
|
||||
not Notanamine
|
||||
tla Triletramine</code></pre>
|
||||
<p>Interestingly, the TLI are the perfect mnemonics for C language
|
||||
source. For example, <code>met</code> is
|
||||
“<code>main()'s Exit Type</code>” (<code>int</code>), <code>ala</code>
|
||||
is “<code>A Large Algebraic</code>” (<code>bignum</code>),
|
||||
<code>ile</code> an “<code>Incremented Local Entity</code>” (index
|
||||
counter), <code>gly</code> means “<code>Grow Larger memorY</code>”,
|
||||
<code>gln</code> is “<code>Grown Larger Now</code>” (after
|
||||
<code>realloc(3)</code>), <code>not</code> is a
|
||||
“<code>Not Overflowing Type</code>” (recursive!), <code>unk</code> is
|
||||
the “<code>UNit (Known as 1)</code>”, <code>trp</code> is the
|
||||
“<code>Tabula Rasa Product</code>” (zero), <code>phe</code> is
|
||||
“<code>Print HEx</code>” and so on.</p>
|
||||
<h3 id="convert-ansi-trigraphs-to-ascii">Convert ANSI trigraphs to
|
||||
ASCII</h3>
|
||||
<p>Interestingly, the TLI are the perfect mnemonics for C language source.
|
||||
For example, <code>met</code> is “<code>main()'s Exit Type</code>” (<code>int</code>), <code>ala</code> is “<code>A Large Algebraic</code>” (<code>bignum</code>), <code>ile</code> an “<code>Incremented Local Entity</code>” (index
|
||||
counter), <code>gly</code> means “<code>Grow Larger memorY</code>”, <code>gln</code> is “<code>Grown Larger Now</code>”
|
||||
(after <code>realloc(3)</code>), <code>not</code> is a “<code>Not Overflowing Type</code>” (recursive!), <code>unk</code>
|
||||
is the “<code>UNit (Known as 1)</code>”, <code>trp</code> is the “<code>Tabula Rasa Product</code>” (zero),
|
||||
<code>phe</code> is “<code>Print HEx</code>” and so on.</p>
|
||||
<h3 id="convert-ansi-trigraphs-to-ascii">Convert ANSI trigraphs to ASCII</h3>
|
||||
<p>Huh??!</p>
|
||||
<h3 id="c-pre-process-the-source-ignoring-include-lines">C pre-process
|
||||
the source ignoring <code>#include</code> lines</h3>
|
||||
<p>Wow, an identity operation (except for the
|
||||
<code><stdint.h></code> and <code>EOF + __STDC__</code>
|
||||
<h3 id="c-pre-process-the-source-ignoring-include-lines">C pre-process the source ignoring <code>#include</code> lines</h3>
|
||||
<p>Wow, an identity operation (except for the <code><stdint.h></code> and <code>EOF + __STDC__</code>
|
||||
trivialities). Did you gain any insight through this?</p>
|
||||
<h3 id="c-pre-process-the-source-ignoring-define-and-include-lines">C
|
||||
pre-process the source ignoring ‘#define’ and ‘#include’ lines</h3>
|
||||
<p><code>#define</code>? Which <code>#define</code> directives? How many
|
||||
4K source files do you see that don’t use a single <code>#define</code>
|
||||
directive <em>or</em> abuse the build file? Even though the “no
|
||||
<code>#define</code>” rule I submitted myself to made it hard, I could
|
||||
use <code>__LINE__</code> and <code>stdio.h</code> macros
|
||||
<code>EOF</code>, <code>L_tmpnam</code>, <code>BUFSIZ</code>,
|
||||
<code>FILENAME_MAX</code>, <code>TMP_MAX</code> to obfuscate at least
|
||||
something.</p>
|
||||
<h3 id="run-it-through-a-c-beautifier">Run it through a C
|
||||
beautifier</h3>
|
||||
<h3 id="c-pre-process-the-source-ignoring-define-and-include-lines">C pre-process the source ignoring ‘#define’ and ‘#include’ lines</h3>
|
||||
<p><code>#define</code>? Which <code>#define</code> directives? How many 4K source files do you
|
||||
see that don’t use a single <code>#define</code> directive <em>or</em> abuse the build
|
||||
file? Even though the “no <code>#define</code>” rule I submitted myself to made it
|
||||
hard, I could use <code>__LINE__</code> and <code>stdio.h</code> macros <code>EOF</code>, <code>L_tmpnam</code>,
|
||||
<code>BUFSIZ</code>, <code>FILENAME_MAX</code>, <code>TMP_MAX</code> to obfuscate at least something.</p>
|
||||
<h3 id="run-it-through-a-c-beautifier">Run it through a C beautifier</h3>
|
||||
<p>Another identity operation. I’ve done it for you already. Use this
|
||||
<code>.indent.pro</code> with FreeBSD indent:</p>
|
||||
<div class="sourceCode" id="cb14"><pre
|
||||
class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cat .indent.pro</span>
|
||||
<div class="sourceCode" id="cb14"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> cat .indent.pro</span>
|
||||
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> <span class="ex">-bad</span> /<span class="pp">*</span> blank line after decls <span class="pp">*</span>/</span>
|
||||
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> <span class="ex">-bap</span> /<span class="pp">*</span> blank line after functions <span class="pp">*</span>/</span>
|
||||
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a> <span class="ex">-br</span> /<span class="pp">*</span> braces on if line <span class="pp">*</span>/</span>
|
||||
@@ -427,29 +392,25 @@ class="sourceCode sh"><code class="sourceCode bash"><span id="cb14-1"><a href="#
|
||||
<span id="cb14-18"><a href="#cb14-18" aria-hidden="true" tabindex="-1"></a><span class="st"> -Tala</span></span></code></pre></div>
|
||||
<p>It looks like a perfect program should have:</p>
|
||||
<ul>
|
||||
<li>two and a half <code>#include</code>s of non-suspicious standard
|
||||
headers</li>
|
||||
<li>two and a half <code>#include</code>s of non-suspicious standard headers</li>
|
||||
<li>followed by self protection against goofy implementations</li>
|
||||
<li>followed by a handful of <code>typedef</code>s</li>
|
||||
<li>and a pair of file scope objects by necessity</li>
|
||||
<li>prototypes! With parameter names! <code>static</code> for internal
|
||||
linkage even! This <strong>must</strong> be a first in IOCCC
|
||||
history.</li>
|
||||
<li>prototypes! With parameter names! <code>static</code> for internal linkage even! This <strong>must</strong> be a first in IOCCC history.</li>
|
||||
<li>function definitions, <code>main</code> last</li>
|
||||
<li>everything is fully <code>const</code>-poisoned: automatics,
|
||||
statics, arguments, even <code>main</code></li>
|
||||
<li>everything is fully <code>const</code>-poisoned: automatics, statics, arguments, even <code>main</code></li>
|
||||
<li>everything is fully curly braced, even single statements</li>
|
||||
<li>plenty of meaningful TLC (Three Letter Comments)</li>
|
||||
</ul>
|
||||
<p>The program contains not a single <em>magic number</em> (only 0 and
|
||||
powers of 2, each power from 1 to 512) which are obvious to competent
|
||||
software engineers). How many programs have <em>that</em> property? The
|
||||
check for <code>__STDC_VERSION__</code> was a bit tough to arrive at,
|
||||
since 199901L has too many bits set. But I realized that I only needed a
|
||||
number larger than 199409 and less than 199901. 199680 has only 4 bits
|
||||
set and writing it as <code>(256 + 128 + 4 + 2) * 512</code> minimizes
|
||||
the character count. That’s what judges get when they don’t like
|
||||
programs that are longer than they need to be.</p>
|
||||
<p>The program contains not a single <em>magic number</em> (only 0 and powers of
|
||||
2, each power from 1 to 512) which are obvious to competent software
|
||||
engineers). How many programs have <em>that</em> property? The check for
|
||||
<code>__STDC_VERSION__</code> was a bit tough to arrive at, since 199901L has too
|
||||
many bits set. But I realized that I only needed a number larger than
|
||||
199409 and less than 199901. 199680 has only 4 bits set and writing it
|
||||
as <code>(256 + 128 + 4 + 2) * 512</code> minimizes the character count. That’s what
|
||||
judges get when they don’t like programs that are longer than they need
|
||||
to be.</p>
|
||||
<h3 id="examine-the-algorithm">Examine the algorithm</h3>
|
||||
<p>Spoilers ahead. Duh!</p>
|
||||
<p>Pseudocode, with comments matching those in the C source:</p>
|
||||
@@ -469,73 +430,58 @@ programs that are longer than they need to be.</p>
|
||||
<span id="cb15-14"><a href="#cb15-14" aria-hidden="true" tabindex="-1"></a> print n <span class="co">/* 2hx */</span></span>
|
||||
<span id="cb15-15"><a href="#cb15-15" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
|
||||
<span id="cb15-16"><a href="#cb15-16" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
||||
<p><code>Bignum</code>s are represented as the two member
|
||||
<code>struct</code>s:</p>
|
||||
<p><code>Bignum</code>s are represented as the two member <code>struct</code>s:</p>
|
||||
<div class="sourceCode" id="cb16"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="kw">typedef</span> <span class="kw">struct</span> <span class="op">{</span></span>
|
||||
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a> <span class="dt">size_t</span> places<span class="op">;</span> <span class="co">/* number of places in base 2 to the power of (8*sizeof(type)) */</span></span>
|
||||
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a> type <span class="op">*</span>number<span class="op">;</span> <span class="co">/* dynamically allocated memory for number */</span></span>
|
||||
<span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a><span class="op">}</span> bignum</span></code></pre></div>
|
||||
<h3 id="compile-it-with-flags-to-enable-all-warnings">Compile it (with
|
||||
flags to enable all warnings)</h3>
|
||||
<p>Here’s where the program shines brighter than a <a
|
||||
href="https://en.wikipedia.org/wiki/Gamma-ray_burst">gamma-ray
|
||||
<h3 id="compile-it-with-flags-to-enable-all-warnings">Compile it (with flags to enable all warnings)</h3>
|
||||
<p>Here’s where the program shines brighter than a <a href="https://en.wikipedia.org/wiki/Gamma-ray_burst">gamma-ray
|
||||
burst</a>!</p>
|
||||
<p>I challenge you to throw all kinds of compilers, lints, checkers and
|
||||
analyzers at my program and make it find the slightest of issues.</p>
|
||||
<p>Is
|
||||
<code>clang -Wall -Wextra -Weverything -Dtyp=uint32_t prog.c</code> all
|
||||
you can do? Clang has implemented a new warning? Bring it on!</p>
|
||||
<p>Is <code>clang -Wall -Wextra -Weverything -Dtyp=uint32_t prog.c</code> all you can
|
||||
do? Clang has implemented a new warning? Bring it on!</p>
|
||||
<h3 id="execute-it">Execute it</h3>
|
||||
<p>May you win the jackpot!</p>
|
||||
<p>For least surprising results, the execution character set should be
|
||||
ASCII. The program computes four bits from every character in
|
||||
<code>argv[1]</code> and interprets them as a hex digit. In ASCII the
|
||||
characters <code>a-f</code>, <code>A-F</code> and <code>0-9</code> are
|
||||
converted as expected.</p>
|
||||
<p>This means however, that the program accepts <strong>any
|
||||
string</strong>, turns it into a starting number (which is output as the
|
||||
first line), and starts crunching. Nothing stops you from executing</p>
|
||||
<div class="sourceCode" id="cb17"><pre
|
||||
class="sourceCode sh"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./prog</span> <span class="st">"</span><span class="va">$(</span><span class="fu">cat</span> prog.c<span class="va">)</span><span class="st">"</span> <span class="co"># Kind of quine?</span></span>
|
||||
<p>For least surprising results, the execution character set should be ASCII. The
|
||||
program computes four bits from every character in <code>argv[1]</code> and interprets them
|
||||
as a hex digit. In ASCII the characters <code>a-f</code>, <code>A-F</code> and <code>0-9</code> are converted as
|
||||
expected.</p>
|
||||
<p>This means however, that the program accepts <strong>any string</strong>, turns it
|
||||
into a starting number (which is output as the first line), and starts
|
||||
crunching. Nothing stops you from executing</p>
|
||||
<div class="sourceCode" id="cb17"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="ex">./prog</span> <span class="st">"</span><span class="va">$(</span><span class="fu">cat</span> prog.c<span class="va">)</span><span class="st">"</span> <span class="co"># Kind of quine?</span></span>
|
||||
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a><span class="ex">./prog</span> <span class="st">"</span><span class="va">$(</span><span class="fu">cat</span> rules guidelines<span class="va">)</span><span class="st">"</span> <span class="co"># A jackpot? Maybe next year...</span></span>
|
||||
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a><span class="ex">./prog</span> <span class="st">"</span><span class="va">$(</span><span class="fu">cat</span> /bin/ls<span class="va">)</span><span class="st">"</span> <span class="co"># Number cut short at first NUL byte.</span></span></code></pre></div>
|
||||
<p>In a certain way, the program is character set and encoding
|
||||
agnostic.</p>
|
||||
<p>In a certain way, the program is character set and encoding agnostic.</p>
|
||||
<h3 id="assumptions-made">Assumptions made</h3>
|
||||
<ul>
|
||||
<li>The <code>EOF</code> macro from <code><stdio.h></code> must
|
||||
expand to <code>-1</code> since it is used to decrement a pointer and do
|
||||
some other math. None of the tools catch this one. The program
|
||||
self-protects against unusual systems with
|
||||
<code>#if EOF + __STDC__</code> followed by <code>#error goofy!</code>.
|
||||
In the rare event your system is goofy, replace all <code>EOF</code>
|
||||
tokens with <code>(-1)</code> and remove the <code>#error</code>
|
||||
directive.</li>
|
||||
<li>The <code>EOF</code> macro from <code><stdio.h></code> must expand to <code>-1</code> since it is used
|
||||
to decrement a pointer and do some other math.
|
||||
None of the tools catch this one. The program self-protects against unusual
|
||||
systems with <code>#if EOF + __STDC__</code> followed by <code>#error goofy!</code>. In the rare event
|
||||
your system is goofy, replace all <code>EOF</code> tokens with <code>(-1)</code> and remove the
|
||||
<code>#error</code> directive.</li>
|
||||
</ul>
|
||||
<p>While the program works best when bytes/characters are octets and the
|
||||
number of bits in a type is <code>sizeof(typ) << 3</code>, it will
|
||||
work correctly on 24-bit or 36-bit systems with 9 bits/byte, or systems
|
||||
where <code>sizeof(typ)</code> is 1 even for <code>int</code> and so on.
|
||||
On such systems, it will only use <code>8 * sizeof(typ)</code> bits per
|
||||
place. It does not work when <code>CHAR_BIT <= 7</code>.</p>
|
||||
number of bits in a type is <code>sizeof(typ) << 3</code>, it will work correctly
|
||||
on 24-bit or 36-bit systems with 9 bits/byte, or systems where
|
||||
<code>sizeof(typ)</code> is 1 even for <code>int</code> and so on. On such systems, it will only
|
||||
use <code>8 * sizeof(typ)</code> bits per place. It does not work when <code>CHAR_BIT <= 7</code>.</p>
|
||||
<h3 id="results-of-various-checkers">Results of various checkers</h3>
|
||||
<h3 id="cppcheck">cppcheck</h3>
|
||||
<p>The open source static checker <a
|
||||
href="http://cppcheck.sourceforge.net/">cppcheck</a> checks various
|
||||
problems with respect to style, performance, portability and general
|
||||
fishiness. To enable all checks, run</p>
|
||||
<div class="sourceCode" id="cb18"><pre
|
||||
class="sourceCode sh"><code class="sourceCode bash"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="ex">cppcheck</span> <span class="at">--enable</span><span class="op">=</span>all <span class="at">--force</span> <span class="at">-I</span>/usr/include <span class="at">-Dtyp</span><span class="op">=</span>uint32_t prog.c</span></code></pre></div>
|
||||
<p>The open source static checker <a href="http://cppcheck.sourceforge.net/">cppcheck</a>
|
||||
checks various problems with respect to style, performance, portability
|
||||
and general fishiness. To enable all checks, run</p>
|
||||
<div class="sourceCode" id="cb18"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="ex">cppcheck</span> <span class="at">--enable</span><span class="op">=</span>all <span class="at">--force</span> <span class="at">-I</span>/usr/include <span class="at">-Dtyp</span><span class="op">=</span>uint32_t prog.c</span></code></pre></div>
|
||||
<p>No issues found.</p>
|
||||
<h3 id="flawfinder">flawfinder</h3>
|
||||
<p>The open source static checker <a
|
||||
href="http://www.dwheeler.com/flawfinder/">flawfinder</a> checks various
|
||||
problems with respect to security like buffer overflows, function
|
||||
arguments to known troublemaker functions and more. It doesn’t need to
|
||||
pre-process code, so can be run without the <code>typ</code> macro being
|
||||
defined:</p>
|
||||
<div class="sourceCode" id="cb19"><pre
|
||||
class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> flawfinder prog.c</span>
|
||||
<p>The open source static checker <a href="http://www.dwheeler.com/flawfinder/">flawfinder</a>
|
||||
checks various problems with respect to security like buffer overflows,
|
||||
function arguments to known troublemaker functions and more. It doesn’t need to
|
||||
pre-process code, so can be run without the <code>typ</code> macro being defined:</p>
|
||||
<div class="sourceCode" id="cb19"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="ex">$</span> flawfinder prog.c</span>
|
||||
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a><span class="ex">Flawfinder</span> version 1.31, <span class="er">(</span><span class="ex">C</span><span class="kw">)</span> <span class="ex">2001-2014</span> David A. Wheeler.</span>
|
||||
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a><span class="ex">Number</span> of rules <span class="er">(</span><span class="ex">primarily</span> dangerous function names<span class="kw">)</span> <span class="er">in</span> <span class="ex">C/C++</span> ruleset: 169</span>
|
||||
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a><span class="ex">Examining</span> prog.c</span>
|
||||
@@ -543,11 +489,10 @@ class="sourceCode sh"><code class="sourceCode bash"><span id="cb19-1"><a href="#
|
||||
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a><span class="ex">ANALYSIS</span> SUMMARY:</span>
|
||||
<span id="cb19-7"><a href="#cb19-7" aria-hidden="true" tabindex="-1"></a><span class="ex">No</span> hits found.</span></code></pre></div>
|
||||
<h4 id="valgrind">valgrind</h4>
|
||||
<p>The open source dynamic checker <a
|
||||
href="http://valgrind.org/">valgrind</a> runs an executable and verifies
|
||||
all memory accesses and (de)allocations for proper bounds and memory
|
||||
leaks. Since the program frees all memory in all possible execution
|
||||
paths, even when it must bail out, valgrind should be happy. An early
|
||||
<p>The open source dynamic checker <a href="http://valgrind.org/">valgrind</a> runs an
|
||||
executable and verifies all memory accesses and (de)allocations for proper
|
||||
bounds and memory leaks. Since the program frees all memory in all possible
|
||||
execution paths, even when it must bail out, valgrind should be happy. An early
|
||||
version of my program however reported this:</p>
|
||||
<pre><code>valgrind --leak-check=full --show-leak-kinds=all ./prog 6
|
||||
[...]
|
||||
@@ -574,18 +519,16 @@ version of my program however reported this:</p>
|
||||
==14615==
|
||||
==14615== For counts of detected and suppressed errors, rerun with: -v
|
||||
==14615== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)</code></pre>
|
||||
<p>From which I concluded that <code>printf(3)</code> allocated a single
|
||||
4K block for which no matching <code>free(3)</code> existed. But how to
|
||||
free memory allocated deep down in the guts of the Standard I/O library?
|
||||
After some serious head scratching it hit me. The only chance I have is
|
||||
telling the system I no longer want to do I/O, maybe then it would free
|
||||
that buffer. A reading of C99 7.19.5.1, “The fclose function”, was
|
||||
encouraging:</p>
|
||||
<p>From which I concluded that <code>printf(3)</code> allocated a single 4K block for
|
||||
which no matching <code>free(3)</code> existed. But how to free memory allocated deep
|
||||
down in the guts of the Standard I/O library? After some serious head
|
||||
scratching it hit me. The only chance I have is telling the system I no
|
||||
longer want to do I/O, maybe then it would free that buffer. A reading
|
||||
of C99 7.19.5.1, “The fclose function”, was encouraging:</p>
|
||||
<blockquote>
|
||||
<p>Whether or not the call succeeds, the stream is disassociated from
|
||||
the file and any buffer set by the <code>setbuf</code> or
|
||||
<code>setvbuf</code> function is disassociated from the stream (and
|
||||
deallocated if it was automatically allocated).</p>
|
||||
<p>Whether or not the call succeeds, the stream is disassociated from the file
|
||||
and any buffer set by the <code>setbuf</code> or <code>setvbuf</code> function is disassociated from the stream
|
||||
(and deallocated if it was automatically allocated).</p>
|
||||
</blockquote>
|
||||
<p>So I <code>fclose(stdout)</code> before returning and now:</p>
|
||||
<pre><code>valgrind --leak-check=full --show-leak-kinds=all ./prog 6
|
||||
@@ -614,23 +557,20 @@ deallocated if it was automatically allocated).</p>
|
||||
==14571== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)</code></pre>
|
||||
<p>A squeaky clean valgrind result!</p>
|
||||
<h4 id="flexelint">FlexeLint</h4>
|
||||
<p>FlexeLint is a commercial lint tool by <a
|
||||
href="http://www.gimpel.com/html/index.htm">Gimpel Software</a>. It
|
||||
supports nearly a thousand checks, broadly categorized into 4
|
||||
levels,</p>
|
||||
<p>FlexeLint is a commercial lint tool by <a href="http://www.gimpel.com/html/index.htm">Gimpel
|
||||
Software</a>. It supports nearly a
|
||||
thousand checks, broadly categorized into 4 levels,</p>
|
||||
<ol type="1">
|
||||
<li>Syntax errors only (messages 1 to 399)</li>
|
||||
<li>Warnings (messages 400 to 699)</li>
|
||||
<li>Informational messages (700 to 899)</li>
|
||||
<li>Elective notes (900 to 1000 and > 9000)</li>
|
||||
</ol>
|
||||
<p>There is an <a
|
||||
href="http://www.gimpel-online.com/OnlineTesting.html">on-line
|
||||
demonstrator</a> you can use for checking your C programs and I highly
|
||||
recommend trying it. For a start, paste the well know first program in
|
||||
the form and press “Analyze Code”. Note the FlexeLint configuration
|
||||
options in comments (no space between <code>/*</code> and
|
||||
<code>lint</code>).</p>
|
||||
<p>There is an <a href="http://www.gimpel-online.com/OnlineTesting.html">on-line
|
||||
demonstrator</a> you can
|
||||
use for checking your C programs and I highly recommend trying it. For a start,
|
||||
paste the well know first program in the form and press “Analyze Code”. Note
|
||||
the FlexeLint configuration options in comments (no space between <code>/*</code> and <code>lint</code>).</p>
|
||||
<div class="sourceCode" id="cb22"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a> <span class="co">/*lint -w4 turn on everything */</span></span>
|
||||
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a> <span class="co">/*lint +esym(534,*) no demonstrator defaults */</span></span>
|
||||
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a> <span class="co">/*lint -e966 indirectly included header file not used */</span></span>
|
||||
@@ -644,34 +584,28 @@ options in comments (no space between <code>/*</code> and
|
||||
<span id="cb22-11"><a href="#cb22-11" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="dv">0</span><span class="op">;</span></span>
|
||||
<span id="cb22-12"><a href="#cb22-12" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span></code></pre></div>
|
||||
<p>Possible checks include those for MISRA 2004 compliance verification.
|
||||
The <a
|
||||
href="https://en.wikipedia.org/wiki/Motor_Industry_Software_Reliability_Association">Motor
|
||||
Industry Software Reliability Association</a> has produced a <a
|
||||
href="http://doc.hcc-embedded.com/display/CODING/MISRA+Rules">list of
|
||||
121 required and 20 advisory rules</a> for C programming. I am proud to
|
||||
report that my program fulfills <em>almost all</em> rules. To assess the
|
||||
few exceptions, one has to understand that MISRA rules are geared
|
||||
towards embedded systems used in the automotive industry. That’s why
|
||||
features like <code>malloc(3)</code> and <code>printf(3)</code> are
|
||||
right out. But that’s too restrictive for an IOCCC hosted application,
|
||||
so I ignored these:</p>
|
||||
The <a href="https://en.wikipedia.org/wiki/Motor_Industry_Software_Reliability_Association">Motor Industry Software Reliability
|
||||
Association</a>
|
||||
has produced a <a href="http://doc.hcc-embedded.com/display/CODING/MISRA+Rules">list of 121 required and 20 advisory
|
||||
rules</a> for C
|
||||
programming. I am proud to report that my program fulfills <em>almost all</em>
|
||||
rules. To assess the few exceptions, one has to understand that MISRA
|
||||
rules are geared towards embedded systems used in the automotive
|
||||
industry. That’s why features like <code>malloc(3)</code> and <code>printf(3)</code> are right out.
|
||||
But that’s too restrictive for an IOCCC hosted application, so I ignored
|
||||
these:</p>
|
||||
<ul>
|
||||
<li>17.1 Pointer arithmetic shall only be applied to pointers that
|
||||
address an array or array element.</li>
|
||||
<li>17.4 Array indexing shall be the only allowed form of pointer
|
||||
arithmetic.</li>
|
||||
<li>17.1 Pointer arithmetic shall only be applied to pointers that address an array or array element.</li>
|
||||
<li>17.4 Array indexing shall be the only allowed form of pointer arithmetic.</li>
|
||||
<li>20.4 Dynamic heap memory allocation shall not be used.</li>
|
||||
<li>20.9 The input/output library stdio.h shall not be used in
|
||||
production code.</li>
|
||||
<li>20.11 The functions abort, exit, getenv, and system from the library
|
||||
stdlib.h shall not be used.</li>
|
||||
<li>20.9 The input/output library stdio.h shall not be used in production code.</li>
|
||||
<li>20.11 The functions abort, exit, getenv, and system from the library stdlib.h shall not be used.</li>
|
||||
</ul>
|
||||
<p>I started out with enabling <em>all</em> messages using
|
||||
<code>FlexeLint</code>’s <code>-w4</code> option and disabling all noise
|
||||
from system headers. Then I dealt with the remaining messages by
|
||||
addressing them or suppressing them in such a way that the set of
|
||||
suppressions was minimal. At the end of the day, this is what
|
||||
remained:</p>
|
||||
<p>I started out with enabling <em>all</em> messages using <code>FlexeLint</code>’s <code>-w4</code>
|
||||
option and disabling all noise from system headers. Then I dealt with
|
||||
the remaining messages by addressing them or suppressing them in such a way
|
||||
that the set of suppressions was minimal. At the end of the day, this is
|
||||
what remained:</p>
|
||||
<pre><code> // === Tested with FlexeLint 9.00L on FreeBSD 11 ===
|
||||
// Compiler:
|
||||
// "4.2.1 Compatible FreeBSD Clang 3.6.1 (tags/RELEASE_361/final 237755)"
|
||||
@@ -735,48 +669,39 @@ remained:</p>
|
||||
-e9092 // NULL does not expand to a pointer (but plain 0)</code></pre>
|
||||
<h3 id="compulsory-obfuscations">Compulsory obfuscations</h3>
|
||||
<p>Which of the rules cause which obfuscation?</p>
|
||||
<p>MISRA 6.1: “The plain <code>char</code> type shall be used only for
|
||||
the storage and use of character values.” This forbids using character
|
||||
constants in expressions other than assignments to <code>char</code>
|
||||
objects. A consequence is that printing digits with
|
||||
<code>'0' + digit</code> is not allowed (even though <code>'0'</code> is
|
||||
technically an <code>int</code>!) so I am forced to output hex digits
|
||||
with</p>
|
||||
<p>MISRA 6.1: “The plain <code>char</code> type shall be used only for the storage and
|
||||
use of character values.” This forbids using character constants in
|
||||
expressions other than assignments to <code>char</code> objects. A consequence is
|
||||
that printing digits with <code>'0' + digit</code> is not allowed (even though
|
||||
<code>'0'</code> is technically an <code>int</code>!) so I am forced to output hex digits with</p>
|
||||
<div class="sourceCode" id="cb24"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>printf<span class="op">(</span><span class="st">"</span><span class="sc">%c</span><span class="st">"</span><span class="op">,</span> <span class="op">(</span>met<span class="op">)</span>tyr <span class="op">+</span> <span class="dv">32</span> <span class="op">+</span> <span class="dv">16</span> <span class="op">+</span> <span class="op">((</span><span class="dv">8</span> <span class="op">+</span> EOF<span class="op">)</span> <span class="op">*</span> <span class="op">((</span>met<span class="op">)</span>tyr <span class="op">/</span> <span class="op">(</span><span class="dv">8</span> <span class="op">+</span> <span class="dv">2</span><span class="op">))));</span></span></code></pre></div>
|
||||
<p>because of the “no magic numbers other than powers of two” rule. How
|
||||
is this an improvement over
|
||||
<code>printf("%c", '0' + tyr + 7 * (tyr / 10)</code>, MISRA?</p>
|
||||
<p>MISRA 6.3: “<code>typedef</code>s that indicate size and signedness
|
||||
should be used in place of the basic types.” Well, if you can’t infer
|
||||
the size and signedness from <code>typedef int met</code>, you’re not a
|
||||
real C programmer.</p>
|
||||
<p>MISRA 10.5: “If the bitwise operators <code>~</code> and
|
||||
<code><<</code> are applied to an operand of underlying type
|
||||
<code>unsigned char</code> or <code>unsigned short</code>, the result
|
||||
shall be immediately cast to the underlying type of the operand.”
|
||||
Because the program must work for any unsigned type chosen for the
|
||||
<code>typ</code> macro, including the narrow types enumerated in the
|
||||
rule, a lot of redundant casting ensues. It gets worse with the next
|
||||
rule…</p>
|
||||
<p>because of the “no magic numbers other than powers of two” rule. How is this
|
||||
an improvement over <code>printf("%c", '0' + tyr + 7 * (tyr / 10)</code>, MISRA?</p>
|
||||
<p>MISRA 6.3: “<code>typedef</code>s that indicate size and signedness should be used in
|
||||
place of the basic types.” Well, if you can’t infer the size and
|
||||
signedness from <code>typedef int met</code>, you’re not a real C programmer.</p>
|
||||
<p>MISRA 10.5: “If the bitwise operators <code>~</code> and <code><<</code> are applied to an
|
||||
operand of underlying type <code>unsigned char</code> or <code>unsigned short</code>, the
|
||||
result shall be immediately cast to the underlying type of the operand.”
|
||||
Because the program must work for any unsigned type chosen for the <code>typ</code>
|
||||
macro, including the narrow types enumerated in the rule, a lot of
|
||||
redundant casting ensues. It gets worse with the next rule…</p>
|
||||
<p>MISRA 12.1: “Limited dependence should be placed on the C operator
|
||||
precedence rules in expressions.” This requires parentheses for almost
|
||||
all expressions involving more than one operator, especially those for
|
||||
which a cast is required, leading to hard to understand expressions such
|
||||
as</p>
|
||||
all expressions involving more than one operator, especially those for which
|
||||
a cast is required, leading to hard to understand expressions such as</p>
|
||||
<div class="sourceCode" id="cb25"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="dt">const</span> ser glx <span class="op">=</span> <span class="op">(</span>ser<span class="op">)((</span>asx <span class="op">></span> <span class="op">(</span>ser<span class="op">)</span><span class="dv">64</span><span class="bu">u</span><span class="op">)</span> <span class="op">?</span> <span class="op">(</span>ser<span class="op">)((</span>ser<span class="op">)</span>asx <span class="op">+</span> <span class="op">(</span>ser<span class="op">)</span><span class="dv">8</span><span class="bu">u</span> <span class="op">+</span> <span class="op">(</span>ser<span class="op">)</span><span class="dv">1</span><span class="bu">u</span><span class="op">)</span> <span class="op">:</span> <span class="op">(</span>ser<span class="op">)</span>asx<span class="op">);</span></span>
|
||||
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a>not<span class="op">.</span>not<span class="op">[</span>leu<span class="op">]</span> <span class="op">=</span> <span class="op">(</span>and<span class="op">)((</span>and<span class="op">)</span>not<span class="op">.</span>not<span class="op">[</span>leu<span class="op">]</span> <span class="op">|</span> <span class="op">(</span>and<span class="op">)(((</span>and<span class="op">)</span>glx <span class="op">%</span> <span class="op">(</span>and<span class="op">)</span><span class="dv">16</span><span class="bu">u</span><span class="op">)</span> <span class="op"><<</span> <span class="op">(</span>and<span class="op">)</span>lys<span class="op">));</span></span></code></pre></div>
|
||||
<p>MISRA 14.7: “A function shall have a single point of exit at the end
|
||||
of the function.” Sigh. Since I must use eloquent prototypes (8.1, 16.3,
|
||||
<p>MISRA 14.7: “A function shall have a single point of exit at the end of
|
||||
the function.” Sigh. Since I must use eloquent prototypes (8.1, 16.3,
|
||||
16.4) and static functions (8.10, 8.11), I can only use a few functions.
|
||||
Everything usually written with an early <code>return</code> now cause
|
||||
<em>another useless indent level</em>. The first three <code>if</code>
|
||||
statements in <code>main()</code> cause a silly 24 character indent. The
|
||||
maximum indent is forced to 8, which is way too high for a sane
|
||||
function.</p>
|
||||
<p>MISRA 16.10: “If a function returns error information, then that
|
||||
error information shall be tested.” A cast to <code>void</code> would
|
||||
draw a lint warning, so I use the <code>printf(3)</code> result in
|
||||
expressions,</p>
|
||||
Everything usually written with an early <code>return</code> now cause <em>another
|
||||
useless indent level</em>. The first three <code>if</code> statements in <code>main()</code> cause a
|
||||
silly 24 character indent. The maximum indent is forced to 8, which is way
|
||||
too high for a sane function.</p>
|
||||
<p>MISRA 16.10: “If a function returns error information, then that error
|
||||
information shall be tested.” A cast to <code>void</code> would draw a lint warning, so
|
||||
I use the <code>printf(3)</code> result in expressions,</p>
|
||||
<div class="sourceCode" id="cb26"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a>lys <span class="op">-=</span> <span class="dv">4</span> <span class="op">*</span> printf<span class="op">(</span><span class="st">"</span><span class="sc">%c</span><span class="st">"</span><span class="op">,</span> <span class="op">(</span>met<span class="op">)</span>tyr <span class="op">+</span> <span class="dv">32</span> <span class="op">+</span> <span class="dv">16</span> <span class="op">+</span> <span class="op">((</span><span class="dv">8</span> <span class="op">+</span> EOF<span class="op">)</span> <span class="op">*</span> <span class="op">((</span>met<span class="op">)</span>tyr <span class="op">/</span> <span class="op">(</span><span class="dv">8</span> <span class="op">+</span> <span class="dv">2</span><span class="op">))));</span></span>
|
||||
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a>val <span class="op">+=</span> printf<span class="op">(</span><span class="st">"</span><span class="sc">\n</span><span class="st">"</span><span class="op">)</span> <span class="op">/</span> <span class="op">((</span>__LINE__ <span class="op">*</span> L_tmpnam<span class="op">)</span> <span class="op">+</span> TMP_MAX<span class="op">);</span></span>
|
||||
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a>val <span class="op">-=</span> <span class="op">(</span>printf<span class="op">(</span><span class="st">" </span><span class="sc">%d\n</span><span class="st">"</span><span class="op">,</span> val<span class="op">)</span> <span class="op">></span> BUFSIZ<span class="op">)</span> <span class="op">?</span> FILENAME_MAX <span class="op">:</span> EOF<span class="op">;</span></span></code></pre></div>
|
||||
@@ -784,116 +709,82 @@ expressions,</p>
|
||||
<div class="sourceCode" id="cb27"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a>lys <span class="op">-=</span> <span class="dv">4</span><span class="op">;</span></span>
|
||||
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a><span class="co">/*nop*/</span></span>
|
||||
<span id="cb27-3"><a href="#cb27-3" aria-hidden="true" tabindex="-1"></a><span class="op">++</span>val<span class="op">;</span></span></code></pre></div>
|
||||
<p>MISRA 13.1: “Assignment operators shall not be used in expressions
|
||||
that yield a Boolean value.” Forbids the idiomatic
|
||||
<code>if ((p = malloc(n)) == NULL)</code> and requires separate
|
||||
statements, in other words, bloat.</p>
|
||||
<p>MISRA 13.1: “Assignment operators shall not be used in expressions that
|
||||
yield a Boolean value.” Forbids the idiomatic <code>if ((p = malloc(n)) == NULL)</code> and requires separate statements, in other words, bloat.</p>
|
||||
<p>MISRA 16.7: “A pointer parameter in a function prototype should be
|
||||
declared as pointer to <code>const</code> if the pointer is not used to
|
||||
modify the addressed object.” in conjunction with lint’s “Note 952:
|
||||
Parameter could be declared <code>const</code>” causes
|
||||
<code>const</code>-poisoning for all functions,</p>
|
||||
declared as pointer to <code>const</code> if the pointer is not used to modify the
|
||||
addressed object.” in conjunction with lint’s “Note 952: Parameter could
|
||||
be declared <code>const</code>” causes <code>const</code>-poisoning for all functions,</p>
|
||||
<div class="sourceCode" id="cb28"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a><span class="dt">static</span> <span class="dt">void</span> phe<span class="op">(</span><span class="dt">const</span> ala not<span class="op">);</span></span>
|
||||
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a><span class="dt">static</span> <span class="dt">void</span> gly<span class="op">(</span>ala <span class="op">*</span><span class="dt">const</span> not<span class="op">,</span> <span class="dt">const</span> and his<span class="op">);</span></span>
|
||||
<span id="cb28-3"><a href="#cb28-3" aria-hidden="true" tabindex="-1"></a>met main<span class="op">(</span>met val<span class="op">,</span> <span class="dt">const</span> pro <span class="op">*</span><span class="dt">const</span> his<span class="op">[]);</span></span></code></pre></div>
|
||||
<p>and quite a number of automatic variables.</p>
|
||||
<h3 id="why-the-laugh-and-throw-up-messages">Why the “laugh” and “throw
|
||||
up” messages?</h3>
|
||||
<p>The guidelines state “We like programs that: make us laugh and/or
|
||||
throw up :-) (humor really helps!)”</p>
|
||||
<h3 id="why-the-laugh-and-throw-up-messages">Why the “laugh” and “throw up” messages?</h3>
|
||||
<p>The guidelines state “We like programs that: make us laugh and/or throw
|
||||
up :-) (humor really helps!)”</p>
|
||||
<h3 id="if-you-have-a-128-bit-type">If you have a 128 bit type</h3>
|
||||
<p>If your compiler supports a 128 bit wide type (e.g. clang, gcc) then
|
||||
you can use it via the <code>typ</code> macro:</p>
|
||||
<div class="sourceCode" id="cb29"><pre
|
||||
class="sourceCode sh"><code class="sourceCode bash"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="fu">clang</span> <span class="at">-Dtyp</span><span class="op">=</span>__uint128_t <span class="at">-o</span> prog prog.c</span></code></pre></div>
|
||||
<div class="sourceCode" id="cb29"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="fu">clang</span> <span class="at">-Dtyp</span><span class="op">=</span>__uint128_t <span class="at">-o</span> prog prog.c</span></code></pre></div>
|
||||
<p>Indeed, the program can use (and lints clean for) all of</p>
|
||||
<div class="sourceCode" id="cb30"><pre
|
||||
class="sourceCode sh"><code class="sourceCode bash"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="fu">clang</span> <span class="at">-Dtyp</span><span class="op">=</span>uint8_t <span class="at">-o</span> prog8 prog.c</span>
|
||||
<div class="sourceCode" id="cb30"><pre class="sourceCode sh"><code class="sourceCode bash"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="fu">clang</span> <span class="at">-Dtyp</span><span class="op">=</span>uint8_t <span class="at">-o</span> prog8 prog.c</span>
|
||||
<span id="cb30-2"><a href="#cb30-2" aria-hidden="true" tabindex="-1"></a><span class="fu">clang</span> <span class="at">-Dtyp</span><span class="op">=</span>uint16_t <span class="at">-o</span> prog16 prog.c</span>
|
||||
<span id="cb30-3"><a href="#cb30-3" aria-hidden="true" tabindex="-1"></a><span class="fu">clang</span> <span class="at">-Dtyp</span><span class="op">=</span>uint32_t <span class="at">-o</span> prog32 prog.c</span>
|
||||
<span id="cb30-4"><a href="#cb30-4" aria-hidden="true" tabindex="-1"></a><span class="fu">clang</span> <span class="at">-Dtyp</span><span class="op">=</span>uint64_t <span class="at">-o</span> prog64 prog.c</span>
|
||||
<span id="cb30-5"><a href="#cb30-5" aria-hidden="true" tabindex="-1"></a><span class="fu">clang</span> <span class="at">-std</span><span class="op">=</span>c89 <span class="at">-Dtyp</span><span class="op">=</span><span class="st">"unsigned long"</span> <span class="at">-o</span> prog89 prog.c</span></code></pre></div>
|
||||
<p>This works because the program has no need for corresponding
|
||||
<code>SCN</code> or <code>PRI</code> macros to do the scanning and
|
||||
printing of variables of these types. With a 128 bit type the program
|
||||
can represent numbers up to 340282366920938463463374607431768211457
|
||||
(<code>3.4 * 1000000000000000000000000000000000000000</code>) as a
|
||||
single “place”, enough to explore yet untested numbers for the rest of
|
||||
your life.</p>
|
||||
<h3 id="how-big-a-number-can-i-test-with-4-gb-of-ram">How big a number
|
||||
can I test with 4 GB of RAM?</h3>
|
||||
<p>The number of hex digits in the start number is limited by
|
||||
<code>ARG_MAX</code>, probably minus some overhead for the environment
|
||||
variables (use <a
|
||||
href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/env.html">env(1)</a>
|
||||
to trim your environment). In bits this leaves you with
|
||||
<code>2 to the power of (4 * ARG_MAX)</code>.</p>
|
||||
<p>The algorithm requires two <code>bignum</code>s in memory for
|
||||
addition. If you hit a divergent number, this will cause out-of-memory
|
||||
(“laugh”) somewhere near 2<sup>16,000,000,000</sup>
|
||||
(<code>4GB/2 * 8bits/byte</code>). Sadly, I don’t have a test case
|
||||
:-)</p>
|
||||
<p>How long would it take to overflow the <em>Not Overflowing Type</em>?
|
||||
Lets assume we’re processing 2GB numbers. The program copies, shifts by
|
||||
one, adds and increments 2GB long bit strings, each time completely
|
||||
thrashing the data cache – at <em>all</em> levels. We have a fast
|
||||
machine that can do an iteration in one second, on average. To make
|
||||
things easy, we round up <code>3*n* + 1</code> to <code>4*n</code>, and
|
||||
assume we never need to divide by two (which is quite optimistic). Then
|
||||
each iteration shifts left by 2. This would take 8 billion seconds, or
|
||||
about 250 years. If you want to get famous, you better <em>remove</em>
|
||||
some of the RAM, use an ancient box, or reduce available memory
|
||||
resources with the <code>ulimit(1)</code> built-in of your shell.</p>
|
||||
<p>For all intents and purposes, the <em>Not Overflowing Type</em> keeps
|
||||
the promise!</p>
|
||||
<h2 id="copyright-and-cc-by-sa-4.0-license">Copyright and CC BY-SA 4.0
|
||||
License:</h2>
|
||||
<p>This file is Copyright (c) 2023 by Landon Curt Noll. All Rights
|
||||
Reserved. You are free to share and adapt this file under the terms of
|
||||
this license:</p>
|
||||
<p>This works because the program has no need for corresponding <code>SCN</code> or <code>PRI</code>
|
||||
macros to do the scanning and printing of variables of these types. With a 128
|
||||
bit type the program can represent numbers up to
|
||||
340282366920938463463374607431768211457 (<code>3.4 * 1000000000000000000000000000000000000000</code>) as a single “place”, enough to
|
||||
explore yet untested numbers for the rest of your life.</p>
|
||||
<h3 id="how-big-a-number-can-i-test-with-4-gb-of-ram">How big a number can I test with 4 GB of RAM?</h3>
|
||||
<p>The number of hex digits in the start number is limited by <code>ARG_MAX</code>,
|
||||
probably minus some overhead for the environment variables (use
|
||||
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/utilities/env.html">env(1)</a>
|
||||
to trim your environment). In bits this leaves you with <code>2 to the power of (4 * ARG_MAX)</code>.</p>
|
||||
<p>The algorithm requires two <code>bignum</code>s in memory for addition.
|
||||
If you hit a divergent number, this will cause out-of-memory (“laugh”)
|
||||
somewhere near 2<sup>16,000,000,000</sup> (<code>4GB/2 * 8bits/byte</code>).
|
||||
Sadly, I don’t have a test case :-)</p>
|
||||
<p>How long would it take to overflow the <em>Not Overflowing Type</em>? Lets
|
||||
assume we’re processing 2GB numbers. The program copies, shifts by one,
|
||||
adds and increments 2GB long bit strings, each time completely thrashing
|
||||
the data cache – at <em>all</em> levels. We have a fast machine that can do an
|
||||
iteration in one second, on average. To make things easy, we round up
|
||||
<code>3*n* + 1</code> to <code>4*n</code>, and assume we never need to divide by two (which is
|
||||
quite optimistic). Then each iteration shifts left by 2. This would take
|
||||
8 billion seconds, or about 250 years. If you want to get famous, you
|
||||
better <em>remove</em> some of the RAM, use an ancient box, or reduce available
|
||||
memory resources with the <code>ulimit(1)</code> built-in of your shell.</p>
|
||||
<p>For all intents and purposes, the <em>Not Overflowing Type</em> keeps the promise!</p>
|
||||
<h2 id="copyright-and-cc-by-sa-4.0-license">Copyright and CC BY-SA 4.0 License:</h2>
|
||||
<p>This file is Copyright (c) 2023 by Landon Curt Noll. All Rights Reserved.
|
||||
You are free to share and adapt this file under the terms of this license:</p>
|
||||
<pre><code>Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)</code></pre>
|
||||
<p>For more information, see:
|
||||
https://creativecommons.org/licenses/by-sa/4.0/</p>
|
||||
<p>For more information, see: https://creativecommons.org/licenses/by-sa/4.0/</p>
|
||||
|
||||
<!-- 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-2015schweikhardt"><a name="inventory"></a>Inventory
|
||||
for 2015/schweikhardt</h1>
|
||||
<h1 id="inventory-for-2015schweikhardt"><a name="inventory"></a>Inventory for 2015/schweikhardt</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/schweikhardt/prog.c">prog.c</a>
|
||||
- entry source</li>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/schweikhardt/Makefile">Makefile</a>
|
||||
- entry Makefile</li>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/schweikhardt/prog.orig.c">prog.orig.c</a>
|
||||
- original source</li>
|
||||
<li><a
|
||||
href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/schweikhardt/try.sh">try.sh</a>
|
||||
- how to run</li>
|
||||
<li><a href="2015_schweikhardt.tar.bz2">2015_schweikhardt.tar.bz2</a> -
|
||||
download entry source</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/schweikhardt/prog.c">prog.c</a> - entry source</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/schweikhardt/Makefile">Makefile</a> - entry Makefile</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/schweikhardt/prog.orig.c">prog.orig.c</a> - original source</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/schweikhardt/try.sh">try.sh</a> - how to run</li>
|
||||
<li><a href="2015_schweikhardt.tar.bz2">2015_schweikhardt.tar.bz2</a> - download entry source</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/schweikhardt/.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/schweikhardt/.gitignore">.gitignore</a>
|
||||
- list of files that should not be committed under git</li>
|
||||
<li><a href="https://github.com/ioccc-src/temp-test-ioccc/blob/master/2015/schweikhardt/.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/schweikhardt/.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/schweikhardt/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/schweikhardt/README.md">README.md</a> - markdown source for index.html</li>
|
||||
</ul>
|
||||
|
||||
<!-- END: next line ends content generated by: bin/output-index-inventory.sh -->
|
||||
|
||||
Reference in new issue
Block a user