summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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));
}