C
Chad
Chad said:void calculate(char *value, char first[], char second[])
{
char difference = 0;
char delta = 0;
for( ;*first && *second; first++,second++) {
difference = *first - *second;
delta = delta * 26 + difference;
}
*value = delta;
}
Wouldn't it be more convenient to have the function return the result
rather than assigning it via a pointer parameter?A lot of the engineers at Lawrence Berkeley National Laboratory use
this method. I guess in my case, it's monkey see, monkey do. I don't
know if there is a formal computer science name to this technique or
if this is just some kind of strange Berkeley thing.
A common style is to have functions return a result that indicates
whether they succeeded or not, which means that the actual result has to
be communicated via a pointer argument. For example, a square root
function in this style might look something like this:
int square_root(double *result, double x) {
if (x < 0.0) {
return BAD_ARGUMENT;
}
else {
*result = sqrt(x);
return OK;
}
}
My guess is that that's what's going on at LBNL, and you've
misunderstood it (it doesn't make much sense for a void function to be
written this way).
[...]
Later on today, when I get home from work, I'll try and find some of
the C code from LBNL that uses this type of programming style.