diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-01-26 14:27:45 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-01-26 14:27:45 +1300 |
commit | 71d6c5d17da5162255e77ce2d6e0c44d4db4698e (patch) | |
tree | 3ff0f7bf511e5d9d04e28b89c0a3e9c023244d6c /funcptr.c | |
parent | Add declaration for static int (diff) | |
download | funcptr-71d6c5d17da5162255e77ce2d6e0c44d4db4698e.tar.gz funcptr-71d6c5d17da5162255e77ce2d6e0c44d4db4698e.zip |
Re-use passed pointers for cheap iteration
Diffstat (limited to 'funcptr.c')
-rw-r--r-- | funcptr.c | 14 |
1 files changed, 4 insertions, 10 deletions
@@ -22,18 +22,12 @@ int half(int i) { 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++) { - printf("%d\n", (*(fpv + i))(n)); - } + while (*fpv) + printf("%d\n", (*fpv++)(n)); } int main(int argc, char **argv) { - int i; - for (i = 1; i < argc; i++) { - fpv_exec(fpv, atoi(argv[i])); - } - + for (argv++, argc--; argc; argv++, argc--) + fpv_exec(fpv, atoi(*argv)); exit(EXIT_SUCCESS); } - |