I want to create a function that returns a function that checks whether a given int
is within certain bounds.
Therefore the returned function should only take one parameter, an int
, and return a bool
. This is necessary as the returned function is passed on as a function pointer to another function. So far I would only be able to do it like this:
bool valueIsInBounds(int value) { return value >= 0 && value <= 100; }
int main() {
functionThatTakesAFunction(&valueIsInBounds);
}
0
and 100
are obviously fixed values, and I would like to change that.
What I would like to be able to do is something like this:
??? functionGenerator(int min, int max) { ??? }
int main() {
functionThatTakesAFunction(&(functionGenerator(0, 100)));
}
I know this is doable in other languages, though I don't know how this would be achieved in C.