title: Assigning a non-restricted pointer to a restricted pointer
body: <p>I am recently implementing a function (<code>my_copy()</code>) with restrict pointers as arguments:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void my_copy(int n, int * restrict p, int * restrict q) {
      if (q == NULL) {
          q = calloc(n, sizeof(int));
      }
      while(n-- &gt; 0) {
          *p++ = *q++;
      }
      // Ignore memory leak for now
  }
  
  int main() {
      int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
      int b[10];
      // Copy a to b
      my_copy(10, b, a);
      for (int i = 0; i &lt; 10; i++)
          printf(&quot;%d &quot;, b[i]);
      printf(&quot;\n&quot;);
      // Zero a
      my_copy(10, a, NULL);
      for (int i = 0; i &lt; 10; i++)
          printf(&quot;%d &quot;, a[i]);
      printf(&quot;\n&quot;);
  }
  </code></pre>
  <p>To implement a &quot;default value&quot; in <code>my_copy()</code>, I am assigning to the restricted pointer <code>q</code>. However, I see in <a href="https://en.cppreference.com/w/c/language/restrict" rel="nofollow noreferrer">https://en.cppreference.com/w/c/language/restrict</a> that using restrict incorrectly can lead to undefined behaviors. Especially, I am confused by the sentence &quot;Assignment from one restricted pointer to another is undefined behavior&quot;. Though I believe <code>calloc()</code> will not return a restricted pointer, is my program free of undefined behaviors?</p>