As dasblinkenlight said, if you want to be able to pass two different structures to functions, using void * to pass a shared pointer would be correct, however, it is not type safe and could easily lead to erroneous code.
What functionality are you trying to achieve with two separate structures? Could you consider the possibility of combining information into one structure instead of it and the presence of a print function that displays all non-zero values?
Forgive me, perhaps the non-optimal c code, I am far from an expert, this is just to illustrate the point :)
typedef struct datastruct { int a; int b; float c; } datastruct; void printData(datastruct *d){ printf("Data:\n") printf((d->a) ? "a=%d", a : ""); printf((d->b) ? "b=%d", b : ""); printf((d->c) ? "c=%.2f", c : ""); printf("\n"); } int main(void) { datastruct data = {0}; printData(&data); return 0; }
source share