Hi,

> I have written my dispose
> function, I get as parameter a void pointer,
> which it seems I must free too. However its prototype is like:
> 
>     typedef void (*gl_setelement_dispose_fn) (const void *elt);
> 
> Then, if I declare my function with a non-const type as first
> argument, it will warn me by conflict at prototype.
> On the other hand, I declare it as const. It warn me if I try to do
> free() on it.

The elements have a type of 'const void *' because the ordered-set
implementation does not need write access to the memory pointed to by the
pointers.

But here, in the dispose function, you need write access. So you need to
cast from 'const void *' to 'void *' inside your dispose function. The
cast is valid because you guarantee that you have allocated each element
with malloc(), realloc(), or calloc().

(In C++, one would have used a template with a type parameter that would be
either 'const foo *' or 'foo *'. But this here is C, not C++.)

Bruno


Reply via email to