Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With the declaration <code>unsigned long *points</code>, <code>points</code> is a pointer. It points to the beginning of an array. <code>arr[x]</code> is the same as <code>*(arr + x)</code>, so whether <code>arr</code> is an array (in which case, it takes the address of the array, adds <code>x</code>, and dereferences the 'pointer') or a pointer (in which case, it takes the pointer value, adds <code>x</code>, and dereferences the pointer), <code>arr[0]</code> still gets the same array access.</p> <p>In this case, you can't declare <code>points</code> as an array because you're not <em>using</em> it as an array - you're using it as a pointer, which points to an array. A pointer is a shallow copy - if you change the data pointed to by a pointer, it changes the original data. To create a regular array, you'd need to do a deep copy, which would prevent your changes in <code>pointer</code> from affecting the array <code>self</code>, which is ultimately what you want.</p> <p>In fact, you could rewrite the whole thing without <code>points</code>:</p> <pre><code>void SetSpanSeries(Series *self, const Span *src) { 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>As to your second example, yes, <code>points[0].lo</code> is correct. <code>points-&gt;lo</code> would also be correct, so long as you're only accessing <code>points[0]</code>. (Or <code>self-&gt;points[0].lo</code> if you take out <code>points</code> entirely.)</p>
    singulars
    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