title: Pointer casting and "free" in C
body: <p>Given the following code:</p>
  
  <pre><code>RTIME *rtCreate(void)
  {
      RTIME *rtime;
  
      rtime = malloc(sizeof(*rtime));
  
      if (rtime != NULL)
      {
          /* Initialization stuff */
      }
  
      return rtime;
  }
  
  void rtDestroy(RTIME **rtime)
  {
      if (*rtime != NULL)
      {
          free(*rtime);
          *rtime = NULL;
      }
  }
  </code></pre>
  
  <p>what would cause GCC to complain that "passing argument 1 of 'free' discards qualifiers from pointer target type"? I understood that it was unnecessary to cast the result of malloc (as discussed <a href="https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc">here</a>), as the pointer to void is automagically converted to the correct type. Why then does the compiler seem to be implying that I must cast <code>*rtime</code> before it may be freed?</p>
  
  <p>EDIT:- RTIME is defined as follows.</p>
  
  <pre><code>typedef struct RTIME
  {
      uint8 Sec;
      uint8 Min;
      uint8 Hour;
      uint8 DayOfWeek;
      uint8 DayOfMonth;
      uint16 DayOfYear;
      uint8 Month;
      uint16 Year;
  } volatile RTIME;
  </code></pre>