Skip to content

Instantly share code, notes, and snippets.

@zoeisnowooze
Created September 5, 2022 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoeisnowooze/c418fa9d9d129ba8d0599c5d64bfe81f to your computer and use it in GitHub Desktop.
Save zoeisnowooze/c418fa9d9d129ba8d0599c5d64bfe81f to your computer and use it in GitHub Desktop.
#include <stdbool.h>
#include <stdio.h>
typedef bool (*gen_f)(size_t *i);
gen_f from_to(size_t from, size_t to) {
size_t i = from;
bool g(size_t * j) {
if (i <= to) {
*j = i++;
return true;
} else {
return false;
}
}
return g;
}
int main(int argc, char **argv) {
gen_f gen = from_to(5, 7);
size_t i;
while (gen(&i)) {
printf("%ld\n", i);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment