Re: storing related structs



Gray Alien wrote, On 30/06/07 12:28:
I have two related structs:

struct A

<snip>

struct B

<snip>

These structures (not pointers to them), need to be stored in a another struct:

struct C
{
unsigned id ;
char name ;
DATA_TYPE the_struct ;
};


Where DATA_TYPE is EITHER a struct A or struct B.

For compatability with existing libraries, I cannot use a void * (for instance), and cast between struct A and B.

Is there a soln to this problem ?

Yes, use a union of the two struct types. Obviously you need something to indicate what is stored so you know how to access it.
--
Flash Gordon
.



Relevant Pages