c struct pointer issues
Posted
by clear2k
on Stack Overflow
See other posts from Stack Overflow
or by clear2k
Published on 2010-03-23T14:36:09Z
Indexed on
2010/03/23
14:43 UTC
Read the original article
Hit count: 491
I'm trying to cast a struct into another struct but I'm having incompatible pointer issues within the cast and the malloc under some_func
(structs layout are the same)
struct stu1 **some_func(struct stu1 *my_struct)
{
my_struct = (struct stu1 **)malloc(sizeof(struct stu1 *)*total_size);
for(i=0;i<20;i++){
my_struct[i] = (struct stu1 *)malloc(sizeof(struct stu1));
printf("%s",my_struct[i++]->a);
}
}
int main()
{
struct stu1 **my_struct;
struct stu2 **my_struct2;
struct stu3 **my_struct3;
my_struct = some_func(my_struct);
my_struct2 = (struct stu2**)some_func((struct stu1*)my_struct2);
my_struct3 = (struct stu3**)some_func((struct stu1*)my_struct3);
}
© Stack Overflow or respective owner