Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>for loop condition</h2> <pre><code>i["]&lt;i;++i){--i;}"] </code></pre> <p>This expression takes advantage of the fact that array indexing is commutative in C. It is equivalent to.</p> <pre><code>"]&lt;i;++i){--i;}"[i] </code></pre> <p>So the loop will terminate when the character at position <code>i</code> is <code>\0</code>, i.e., at the end of the string, which is 14 characters long (which happens to be the same length as "hello, world!\n"). So the <code>for</code> loop condition can be rewritten as:</p> <pre><code>i != 14 </code></pre> <h2>character arithmetic</h2> <pre><code>read('-' - '-', i++ + "hello, world!\n", '/' / '/') </code></pre> <p><code>char</code> is an integer type, and thus:</p> <ul> <li><code>'-' - '-'</code> is 0</li> <li><p><code>'/' / '/'</code> is 1</p> <p>read(0, i++ + "hello, world!\n", 1)</p></li> </ul> <hr> <p>After fixing all the compiler warnings (like implicit int to pointer conversion), and simplifying the things mentioned above, the code becomes:</p> <pre><code>#include &lt;unistd.h&gt; int i = 0; void read2(int, char*, int); int main() { while (i != 14) { read2(0, i++ + "hello, world!\n", 1); } return 0; } void read2(int j, char* i, int p) { write(j / p + p, i-- - j, 1); } </code></pre> <p>(I renamed <code>read</code> to <code>read2</code> to avoid conflicting with the Unix <code>read</code> function.)</p> <p>Note that the <code>j</code> and <code>p</code> arguments to <code>read2</code> are unneeded, as the function is always called with j=0 and p=1.</p> <pre><code>#include &lt;unistd.h&gt; int i = 0; void read2(char*); int main() { while (i != 14) { read2(i++ + "hello, world!\n"); } return 0; } void read2(char* i) { write(1, i--, 1); } </code></pre> <p>The call <code>write(1, i--, 1)</code> writes 1 character from <code>i</code> to file descriptor 1 (stdout). And the postdecrement is superfluous because this <code>i</code> is a local variable never referenced again. So this function is equivalent to <code>putchar(*i)</code>.</p> <p>Inlining the <code>read2</code> function within the main loop gives</p> <pre><code>#include &lt;stdio.h&gt; int i = 0; int main() { while (i != 14) { putchar(*(i++ + "hello, world!\n")); } return 0; } </code></pre> <p>for which the meaning is obvious.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload