Here's something
Code:
#include<stdio.h>
#define MAX_TERMS 20
typedef int (*fnptr)(float,float);
// comparison functions
int cmp_lt ( float a, float b ) {
return a < b;
}
int cmp_le ( float a, float b ) {
return a <= b;
}
int cmp_eq ( float a, float b ) {
return a == b;
}
int cmp_ge ( float a, float b ) {
return a >= b;
}
int cmp_gt ( float a, float b ) {
return a > b;
}
// contains the functions and data to compare with
struct {
fnptr func;
float data;
} terms[MAX_TERMS];
int maxterms;
void test ( void ) {
float a;
for ( a = 0.0 ; a <= 10.0 ; a += 0.2 ) {
int i, ok = 1;
for ( i = 0 ; i < maxterms && ok ; i++ ) {
ok = ok && terms[i].func( a, terms[i].data );
}
if ( ok ) {
printf( "%f passes filter\n", a );
}
}
}
int main ( ) {
// fill the array with
// >= 2.5 AND < 7.0
terms[0].func = cmp_ge;
terms[0].data = 2.5;
terms[1].func = cmp_lt;
terms[1].data = 7.0;
maxterms = 2;
test();
return 0;
}