For example, I have a given struct X
. And now, I am defining additionally A
, B
and C
. All of them contain the exact same attributes like X
but contain also additional ones.
I've seen the following question: Extending a struct in C
I don't want to make use of this nested thing, also, I never use X
itself. It is only a collection of attributes which appear in all other structures.
I was pondering about just defining the content of X
as macro and use it in the definitions of the other structs. For example:
#ifndef
#define X \
char *some_char_arr; \
int *some_int_arr;
#endif
struct A {
X
int specific_to_a[10];
}
struct B {
X
int specific_to_b[20];
}
struct C {
X
int specific_to_c[30];
}
Would that be an adequate solution or is there something better? Or is there any problem with this approach?