I have created a dynamic array struct Vector
whose internals I keep hidden from users. Instead, functions are provided to interact with them, such as
bool Vector_push(struct Vector *vector, const void *value)
To help with the popping of elements, the struct holds a pointer to the function that properly deletes each element. This function is set with the function:
void Vector_set_type_destructor(struct Vector *vector, void (*type_destructor)(void *))
I felt it was a little odd to provide a setter without a getter, so I quickly added the following function.
const void (*Vector_type_destructor(const struct Vector *vector))(void *);
Notice how I added the const
keyword, as I wanted the type destructor to only be modifiable through the setter, and not through the returned pointer. However, I received the following warning from clang.
src/Vector.c:184:66: warning: function cannot return qualified void type
'const void' [-Wqualified-void-return-type]
const void (*Vector_type_destructor(const struct Vector *vector))(void *) {
^
src/Vector.c:185:12: warning: incompatible pointer types returning
'void (*const)(void *)' from a function with result type
'const void (*)(void *)' [-Wincompatible-pointer-types]
return vector->type_destructor;
How do I properly return the pointer void (*type_destructor)(void *)
through the function without exposing it to possible modification?