I would like to do in C code something like that to call one function with can operate on two similar but not the same struct. Now I have two function that do the same but different type data. I can't change struct to the same data type. The struct must have different data type. I tried by void pointer but doesn't work. Dynamic cast pointer but I don't think it's possible in C code. I can't use allocate memory dynamically malloc etc. It is possible to implement?
typedef struct st1_tag
{
uint32_t a;
uint16_t b;
uint16_t tab[10];
}st1_t;
typedef struct st2_tag
{
uint8_t a;
uint16_t b;
uint32_t tab[10];
}st2_t;
...
st1_t x1;
st2_t x2;
...
void foo_1(void)
{
if(x1.b > 2)
{
//to do someting on data struct x1
}
}
void foo_2(void)
{
if(x2.b > 2)
{
//to do something similar like in foo1 but data type field of struct are not the same.
}
}
void foo3(void)
{
foo1();
foo2();
}