summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-01-26 13:40:56 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-01-26 13:40:56 +1300
commit368de8d512c6faa0cedd8de06f5e1885a8f22d10 (patch)
treef146fbe522f62c751b6da224f0268c26329bd60f
parentRefactor targets into list (diff)
downloadfuncptr-368de8d512c6faa0cedd8de06f5e1885a8f22d10.tar.gz
funcptr-368de8d512c6faa0cedd8de06f5e1885a8f22d10.zip
Move fpv to be static file var
-rw-r--r--funcptr.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/funcptr.c b/funcptr.c
index de77066..39cb843 100644
--- a/funcptr.c
+++ b/funcptr.c
@@ -18,6 +18,8 @@ int half(int i) {
return i / 2;
}
+static int (*fpv[])(int) = {doub, trip, half, NULL};
+
void fpv_exec(int (**fpv)(int), int n) {
int i;
for (i = 0; *(fpv + i) != NULL; i++) {
@@ -26,14 +28,6 @@ void fpv_exec(int (**fpv)(int), int n) {
}
int main(int argc, char **argv) {
- int (**fpv)(int);
- fpv = calloc(4, sizeof(int (*)(int)));
-
- fpv[0] = doub;
- fpv[1] = trip;
- fpv[2] = half;
- fpv[3] = NULL;
-
for (argv++, argc--; argc; argv++, argc--) {
fpv_exec(fpv, atoi(*argv));
}