Created
February 27, 2023 07:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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