Let's assume that I declared a C struct for holding configuration information, which has lots of fields(~30), e.g.:
struct config {
int a;
int b;
int c;
...
char *str1;
char *str2;
...
};
What is the best way to compare two structs without simply enumerating and comparing each element? Of course I could use the following code but my question is, is there an easier way to achieve this?
static int
cmpInstances(struct config *l, struct config *r) {
return (
l->a == r->a &&
l->b == r->b &&
l->c == r->c &&
!strcmp(l->str1, r->str1) &&
!strcmp(l->str2, r->str2)
);
}
Is there some macro that could do that? For example:
cmpInstancesViaMacro(a,b,c) would expand into
l->a == r->a &&
l->b == r->b &&
l->c == r->c