Taking your code and making an SSCCE from it, like so:
#include <stdlib.h>
struct RTIME { int a; int b; };
typedef const struct RTIME RTIME;
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;
}
}
Compiling with GCC 4.7.1 and the command line:
$ gcc -O3 -g -std=c99 -Wall -Wextra -Wmissing-prototypes -c mf.c
mf.c:6:8: warning: no previous prototype for ‘rtCreate’ [-Wmissing-prototypes]
mf.c:20:6: warning: no previous prototype for ‘rtDestroy’ [-Wmissing-prototypes]
mf.c: In function ‘rtDestroy’:
mf.c:24:9: warning: passing argument 1 of ‘free’ discards ‘const’ qualifier from pointer target type [enabled by default]
In file included from mf.c:1:0:
/usr/include/stdlib.h:160:7: note: expected ‘void *’ but argument is of type ‘const struct RTIME *’
$
Omit the const
and you only get the (valid) warnings about the missing prototypes.
I'm guessing you're using an older version of GCC (because older versions don't include the extra information in the note:
line), and that somehow or other your typedef
for RTIME
includes a const
.
As a general rule, you don't want const
in a typedef
, but there are bound to be exceptions to the rule.
It turns out from the edited question that the qualifier was volatile
rather than const
. When the typedef
in my sample code is changed, GCC 4.7.1 says:
mf.c:6:8: warning: no previous prototype for ‘rtCreate’ [-Wmissing-prototypes]
mf.c:20:6: warning: no previous prototype for ‘rtDestroy’ [-Wmissing-prototypes]
mf.c: In function ‘rtDestroy’:
mf.c:24:9: warning: passing argument 1 of ‘free’ discards ‘volatile’ qualifier from pointer target type [enabled by default]
In file included from mf.c:1:0:
/usr/include/stdlib.h:160:7: note: expected ‘void *’ but argument is of type ‘volatile struct RTIME *’
When I compile with the system GCC, I get a simpler, less precise error message:
mf.c:7: warning: no previous prototype for ‘rtCreate’
mf.c:21: warning: no previous prototype for ‘rtDestroy’
mf.c: In function ‘rtDestroy’:
mf.c:24: warning: passing argument 1 of ‘free’ discards qualifiers from pointer target type
This is from Apple's GCC:
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
So, the qualifier was volatile
rather than const
.
One good reason to try to upgrade to GCC 4.7.x is that the error messages are much improved over earlier versions. The improved messages are also in 4.6.0; the messages in 4.5.2 were the older style, less informative messages.