Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The ability to treat a pointer as an array definitely confuses most C beginners. Arrays even <em>decay</em> to pointers when passed as arguments to functions, giving the impression that arrays and pointers are completely interchangeable -- they aren't. An excellent description is in <a href="http://rads.stackoverflow.com/amzn/click/0131774298" rel="nofollow">Expert C Programming: Deep C Secrets</a>. (This is one of my favorite books; it's strongly recommended if you intend to understand C.)</p> <p>Anyway, writing <code>pointer[2]</code> is the same as <code>*(pointer+2)</code> -- the array syntax is far easier for most people to read (and write).</p> <p>Since you are using this <code>*points</code> variable to provide easier access to another block of memory (the pointer <code>points</code> in the <code>struct Series</code>), you <em>cannot</em> use an array for your local variable because you cannot re-assign the base of an array to something else. Consider the following illegal code:</p> <pre><code>int foo[10]; int *bar; int wrong[10]; bar = foo; /* fine */ wrong = foo; /* compile error -- cannot assign to the array 'wrong' */ </code></pre> <p>Another option for re-writing this code is to remove the temporary variable:</p> <pre><code>if (src-&gt;lo &lt; src-&gt;hi) { self-&gt;points[0] = src-&gt;lo; self-&gt;points[1] = src-&gt;hi; self-&gt;count = 1; } </code></pre> <p>I'm not sure the temporary variable helps with legibility -- it just saved typing a few characters at the expense of adding a <em>lot</em> of characters. (And a confusing variable, too.)</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. This table or related slice is empty.
    1. 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