I don't know why you would ever want to do this, but I was curious if anyone knew the answer. Is it possible at run time to use one struct definition for a while, and then later change that definition?
i.e.
typedef struct
{
int a;
int b;
}my_struct;
and later on...
typedef struct
{
int a;
int b;
int c;
}my_struct;
No, you can't change the definition of a given type, but there's nothing wrong with casting it to a totally different type, assuming the underlying data is similarly laid out and otherwise compatible.
For example, consider:
By casting
xyzzy
to a different but compatible type, you can access the fields in a different way.Keep in mind that compatibility is important and you have to know that the underlying memory will be correctly aligned between the two structures.
You can also do it by placing both structures into a union, using overlapped memory.
If you're talking about runtime polymorphism, then it can be made to work, but you have to know what you're doing. Read ooc.pdf by Axel Schreiner.