title: GCC pure/const functions that accept a pointer argument
body: <p>Can someone please clarify whether (and why) a function can be attributed <code>pure</code> or <code>const</code> if it has a pointer parameter.</p>
  
  <p>According to the <a href="https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Function-Attributes.html" rel="noreferrer">GCC documentation</a>:</p>
  
  <blockquote>
    <p>Some of common examples of pure functions are strlen or memcmp.</p>
  </blockquote>
  
  <p>The whole point of a pure function is that it need only be called once for the same parameters, i.e. the result can be cached if the compiler thinks it fit to do so, however how does this work for memcmp?</p>
  
  <p>for example:</p>
  
  <pre><code>char *x = calloc(1, 8);
  char *y = calloc(1, 8);
  
  if (memcmp(x, y, 8) &gt; 0)
      printf("x &gt; y\n");
  
  x[1] = 'a';
  if (memcmp(x, y, 8) &gt; 0)
      printf("x &gt; y\n");
  </code></pre>
  
  <p>The parameters to the second call to memcmp are identical to the first (the pointers point to the same address), how does the compiler know not to use the result from the first call, if <code>memcmp</code> is pure?</p>
  
  <p>In my case I want to pass an array to a pure function, and calculate the result based on the array alone. Someone reassure me that this is okay, and that when values in the array change but the address does not, my function will be called correctly.</p>