Re: Code consolidation
- From: Zara <yozara@xxxxxxxx>
- Date: Wed, 31 Aug 2005 05:06:46 GMT
Aaron Jackson wrote:
> I am in the process of writing my first large scale program and I find
> myself in the position of writing several copies of functions that do
> the same thing, with mostly the same code, but only slightly different.
(...)
try macros:
#define CHI(funDeclare,specifics)\
double funDeclare{\
int i;\
double deltay,chiSqrd;\
xy_t *data;\
\
chiSqrd = 0.0;\
data = dataList;\
for (i = 0; data != NULL; i++) {\
deltay = data->y - specifics;\
chiSqrd += weight[i] * deltay * deltay;
data = data->next;\
}\
return(chiSqrd);\
}
CHI(
Chisqrd1(double *params, double *weight),
netCarriers(params, data->x)
)
CHI(
Chisqrd2(dopant_t *dopants, double *weight, double *Ef, double Eg),
netIonized(dopants,data->x, Ef[i])
)
I don't like it at all, bit it is a valid solution
Have you read about templates in C++? They could have been a nicer solution!
.
- References:
- Code consolidation
- From: Aaron Jackson
- Code consolidation
- Prev by Date: Re: low-level question
- Next by Date: Re: while (1) vs. for ( ;; )
- Previous by thread: Re: Code consolidation
- Next by thread: Re: Code consolidation
- Index(es):