My code seems to operate fine when I do this, so I was just wondering if it was permissible or if it could lead to unexpected errors. I'm still learning how to deal with void*, and so I'm not entirely sure when I need to cast or (in this case) what exactly needs to be returned.
I have something like this:
struct x
{
int i;
char* s;
}
void* call_me(struct x* some_x)
{
some_x->i = 5;
some_x->s = "hello";
return some_x;
}
I'm not sure what an alternative method would be here (beside to change the function return type, but I need to leave it as void*). Is this approach fine? It compiles and runs how I expect it to, but I'm not sure if that's just coincidental.
Why don't I have to return an object that's void*?
Cin a while, anyway I think that because you are passing a pointer tocall_methe value ofsome_xwill be changed so you don't need to return anything. From memoryvoid *is used for function pointers