summaryrefslogtreecommitdiff
path: root/funcptr.c
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-01-26 14:27:45 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-01-26 14:27:45 +1300
commit71d6c5d17da5162255e77ce2d6e0c44d4db4698e (patch)
tree3ff0f7bf511e5d9d04e28b89c0a3e9c023244d6c /funcptr.c
parentAdd declaration for static int (diff)
downloadfuncptr-71d6c5d17da5162255e77ce2d6e0c44d4db4698e.tar.gz
funcptr-71d6c5d17da5162255e77ce2d6e0c44d4db4698e.zip
Re-use passed pointers for cheap iteration
Diffstat (limited to 'funcptr.c')
-rw-r--r--funcptr.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/funcptr.c b/funcptr.c
index 478beca..33d4154 100644
--- a/funcptr.c
+++ b/funcptr.c
@@ -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);
}
-