Re: storing related structs
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 30 Jun 2007 13:40:38 +0100
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
.
- References:
- storing related structs
- From: Gray Alien
- storing related structs
- Prev by Date: Re: file shredding
- Next by Date: Re: Display C in HTML
- Previous by thread: Re: storing related structs
- Next by thread: Re: storing related structs
- Index(es):
Relevant Pages
|