Patrick Guio <pa*****@fys.uio.no> wrote:
I wonder whether it is possible to simulate simple polymorphism in C?
I explain what I would like to do. I have defined several structures
mapping different header formats. They all have the same size but have
different fields.
So I have something like struct header1, header2 and so on. Now my
question is how would you define/create an array that can contains
pointers to header1, header2 and so on?
Porbably the best solution would be to use a union (in your case, an
array of unions). Then your main worry would be to determine which kind
of struct any one union currently contains, which can easily be solved
by adding a type member as the first member of each struct.
Richard