title: How to write a memcpy function full MISRA:2012 compatible?
body: <p>I wrote this <code>memcpy</code> function, but I still need to disable rules 11.5 and 11.8. Is there a solution to be full MISRA:2012 compatible? </p>
  
  <pre><code>#pragma cstat_suppress="MISRAC2012-Rule-21.6" // Uses of stdio.h were found.
  #include &lt;stdio.h&gt;
  
  #include &lt;stdint.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  extern int main(void);
  
  static int_least8_t _memcpy(void *dst, const void *src, const size_t length)
  {
      #pragma cstat_disable="MISRAC2012-Rule-11.5" // A conversion from a pointer to void into a pointer to object was found.
      int_least8_t* destination = (int_least8_t*)dst;
      #pragma cstat_disable="MISRAC2012-Rule-11.8" // A cast that removes a const or volatile qualification was found.
      const int_least8_t* source = (int_least8_t*)src;
      #pragma cstat_restore="MISRAC2012-Rule-11.5","MISRAC2012-Rule-11.8"
  
      for (size_t i = 0; i &lt; (length / sizeof(int_least8_t)); i++)
      {
          destination[i] = source[i];
      }
      return 0;
  }
  
  int main(void)
  {
      int32_t src[32];
      int32_t dst[32];
  
      (void)memset(src, 0xff, sizeof(src));
  
      (void)_memcpy(dst, src, 128);
  
      for (size_t i = 0; i &lt; (sizeof(src) / sizeof(src[0])); i++)
      {
          (void)printf("%d &lt;=&gt; %d\n", src[i], dst[i]);
      }
  
      return 0;
  }
  </code></pre>
  
  <p>I am using IAR as a compiler and C-STAT for static analysis. </p>