From 368de8d512c6faa0cedd8de06f5e1885a8f22d10 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 26 Jan 2018 13:40:56 +1300 Subject: Move fpv to be static file var --- funcptr.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'funcptr.c') 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)); } -- cgit v1.2.3