I have a struct defined as:
typedef struct {
int type;
void* info;
} Data;
and then i have several other structs that i want to assign to the void* using the following function:
Data* insert_data(int t, void* s)
{
Data * d = (Data*)malloc(sizeof(Data));
d->type = t;
d->info = s;
return d;
}
struct {
...
} Struct#;
then i just call
insert_data(1, variable_of_type_Struct#);
When i compile this it gives a warning
warning: assignment from incompatible pointer type
i tried to cast the variable in the insert to (void*) but didn't work
insert_data(1, (void *) variable_of_type_Struct#);
How can i get rid of this warning?
Thanks
Hope this program helps!
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int type;
void* info;
} Data;
typedef struct {
int i;
char a;
float f;
double d;
}info;
Data* insert_data(int t, void* s)
{
Data * d = (Data*)malloc(sizeof(Data));
d->type = t;
d->info = s;
return d;
}
int main()
{
info in;
Data * d;
d = insert_data(10, &in);
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With