Skip to content

Instantly share code, notes, and snippets.

@WizzyGeek
Created February 27, 2023 07:25
Show Gist options
  • Save WizzyGeek/e67bb37bce05bfc5eb7dc0b7e422218c to your computer and use it in GitHub Desktop.
Save WizzyGeek/e67bb37bce05bfc5eb7dc0b7e422218c to your computer and use it in GitHub Desktop.
Some C code I wrote, maybe useful for switching instead of dumbass switch-case calling
#include<stdio.h>
int map(int *arr, int (*(*foo)(int))(int), int choose) {
printf("%d", foo(choose)(arr[0]));
}
int barfoo(int x) {
return x - 1;
}
int foobar(int x) {
return x + 1;
}
static int (*foo[])(int) = {foobar, barfoo};
int (*func(int x))(int) {
return foo[x];
}
int main() {
int a = 5;
map(&a, func, 1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment