I'm receiving an incompatible pointer type error warning although my code functions properly. First of all, here's a simplified version of my code:
typedef struct {
int field1;
int field2;
} my_struct;
void some_function(void **data){
// do something with *data
}
int main(int argc, char *argv[]){
my_struct *ptr = malloc(sizeof(my_struct));
ptr->field1 = 5;
ptr->field2 = 17;
some_function(&ptr);
}
The my_struct
type is one example, but I'm actually using multiple types, so some_func
must accept void**
, rather than my_struct**
. Each time I call some_func
in the manner above, I recieve the following warning, and yet my code functions properly.
warning: passing argument 1 of ‘my_func’ from incompatible pointer type
I'm unsure of why these types aren't compatible, and would like to remove the warning in some way. For answers, feel free to explain why this is happening and, if possible, how to remove the warning (cpp directive, maybe?). Thanks!
&(void *)
isn't a thing.&
is just an operator, not part of a type. – Saint&(void *)
, I meant the result of&(some_pointer)
. Thanks for the quick replies - I've just gotten started with C. – Parole