I have two functions that differ only in one parameter (different struct) that nearly do the same processing resulting in a lot of duplication of code. See the following simplified example:
struct foo {
int a;
};
struct bar {
int a;
int b;
};
foo(struct foo *f) {
do_b();
// error handling
f->a = 1;
do_c();
// error handling
do_d();
// error handling
}
bar(struct bar *b); {
do_a();
// error handling
b->b = 2;
do_b();
// error handling
b->a = 1;
do_c();
// error handling
do_d();
// error handling
}
Is there some smart way in using only one function eliminating the code duplication?