I have two functions:
void free_this(THIS *this)
{
THIS *this_tmp;
while (this_tmp = this)
{
if (this->str)
free(this->str);
this = this_tmp->next;
free(this_tmp);
}
}
void free_that(THAT *that)
{
THAT *that_tmp;
while (that_tmp = that)
{
if (that->id)
free(that->id);
that = that_tmp->next;
free(that_tmp);
}
}
Since they are very similar I was trying to come up with one function to handle them both. I can already just use a pointer to point to the correct data to free (i.e. point to either str from THIS struct or to id of THAT struct) however I can't figure out how to get around what type of struct is being dealt with since I can't just use a void pointer since void* has no member named 'NEXT'.
Any ideas?
Maybe I should just combine the two structs THIS and THAT into one somehow? here they are:
typedef struct this {
struct this *next;
char *str;
} THIS;
typedef struct that {
struct that *next;
char *id;
unsigned short result;
OTHERTHING *optr;
} THAT;
Could I possibly use the offsetof function somehow to get the next element?