If I pass a void *vptr to a function which takes a other_type *ptr as its arg, will vptr be converted automatically to other_type *? Here is the code,
typedef struct A {
//...
}A;
void bar(A *a)
{
//do something with a
}
int main()
{
A a = {..};
void *vp = &a;
bar(vp); //will vp be converted to A*?
}
Is my code safe or correct?
Yes,
void*is implicitly convertible to any pointer type, and any pointer type is implicitly convertible tovoid*. This is why you do not need to (and should not) cast the return value ofmalloc, for example.