From 80993355ab2244bae06ea170d8cf6f98eb3300e5 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 10 Dec 2019 16:13:48 +1300 Subject: Adjust implementation --- funcptrptr.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'funcptrptr.c') diff --git a/funcptrptr.c b/funcptrptr.c index f52719d..3d2fe69 100644 --- a/funcptrptr.c +++ b/funcptrptr.c @@ -1,5 +1,6 @@ #include #include +#include int doub(int); int trip(int); @@ -40,32 +41,18 @@ void fpvvv_exec(int (****fpvvv)(int), int n) { int main(int argc, char **argv) { int (****fpvvv)(int); - fpvvv = calloc(2, sizeof(int (***)(int))); - - fpvvv[0] = calloc(2, sizeof(int (**)(int))); - fpvvv[1] = calloc(2, sizeof(int (**)(int))); - - fpvvv[0][0] = calloc(4, sizeof(int (*)(int))); - fpvvv[0][1] = calloc(4, sizeof(int (*)(int))); - fpvvv[1][0] = calloc(4, sizeof(int (*)(int))); - fpvvv[1][1] = calloc(4, sizeof(int (*)(int))); - - fpvvv[0][0][0] = doub; - fpvvv[0][0][1] = trip; - fpvvv[0][0][2] = half; - fpvvv[0][0][3] = NULL; - fpvvv[0][1][0] = doub; - fpvvv[0][1][1] = trip; - fpvvv[0][1][2] = half; - fpvvv[0][1][3] = NULL; - fpvvv[1][0][0] = doub; - fpvvv[1][0][1] = trip; - fpvvv[1][0][2] = half; - fpvvv[1][0][3] = NULL; - fpvvv[1][1][0] = doub; - fpvvv[1][1][1] = trip; - fpvvv[1][1][2] = half; - fpvvv[1][1][3] = NULL; + int (*fpv[])(int) = {doub, trip, half, NULL}; + int i, j, im, jm; + im = jm = 2; + + fpvvv = calloc(im, sizeof *fpvvv); + for (i = 0; i < im; i++) { + fpvvv[i] = calloc(jm, sizeof **fpvvv); + for (j = 0; j < jm; j++) { + fpvvv[i][j] = malloc(sizeof fpv); + memcpy(fpvvv[i][j], fpv, sizeof fpv); + } + } for (argv++, argc--; argc; argv++, argc--) fpvvv_exec(fpvvv, atoi(*argv)); -- cgit v1.2.3