A
aurgathor
Howdy,
How do I pass some function a generic comparison
function? I figured out one non-generic case, but
since this code got parameter declarations in two places,
it's obviously not generic.
TIA
#include <stdio.h>
char comp1 ( int, int );
char comp2 ( char, char );
char comp3 ( char*, char* );
char comp1 ( int i1, int i2 ) {
if (i1 == i2) {
return '=';
} else if (i1 > i2) {
return '>';
} else {
return '<';
}
}
/* comp2 & comp3 omitted for brevity */
int some_func ( char (*comp)(int,int)) {
putchar((*comp) (7,8));
putchar((*comp) (8,8));
putchar((*comp) (8,7));
return 0;
}
int main () {
int i;
i = some_func((char (*)(int, int))(comp1));
return 0;
}
How do I pass some function a generic comparison
function? I figured out one non-generic case, but
since this code got parameter declarations in two places,
it's obviously not generic.
TIA
#include <stdio.h>
char comp1 ( int, int );
char comp2 ( char, char );
char comp3 ( char*, char* );
char comp1 ( int i1, int i2 ) {
if (i1 == i2) {
return '=';
} else if (i1 > i2) {
return '>';
} else {
return '<';
}
}
/* comp2 & comp3 omitted for brevity */
int some_func ( char (*comp)(int,int)) {
putchar((*comp) (7,8));
putchar((*comp) (8,8));
putchar((*comp) (8,7));
return 0;
}
int main () {
int i;
i = some_func((char (*)(int, int))(comp1));
return 0;
}