Function Pointer Demo simplified
authorMarkus Bröker <mbroeker@largo.dyndns.tv>
Sun, 26 Jul 2009 18:21:25 +0200
changeset 103 be3fe4a4f097
parent 102 b8ff193b1a01
child 104 b59f1c9895db
Function Pointer Demo simplified It makes more sense to show the basic usage of fps committer: Markus Bröker <mbroeker@largo.homelinux.org>
function_pointers.c
--- a/function_pointers.c
+++ b/function_pointers.c
@@ -1,40 +1,29 @@
 /**
  * function_pointers.c
- * Copyright (C) 2008 Markus Broeker
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 
-typedef struct T {
-    int a;
-    int b;
-} T;
-
-int plus (T t)
+int plus (int a, int b)
 {
-    return t.a + t.b;
+    return a + b;
 }
 
-int minus (T t)
+int minus (int a, int b)
 {
-    return t.a - t.b;
+    return a - b;
 }
 
-int func (T t, int (*ptrFunc) (T))
+int func (int (*ptrFunc) (int, int), int a, int b)
 {
-    return ptrFunc (t);
+    return ptrFunc (a, b);
 }
 
 int main (int argc, char **argv)
 {
-    T t = {
-        .a = 20,
-        .b = 10
-    };
-
-    printf ("Result: %d\n", func (t, &plus));
-    printf ("Result: %d\n", func (t, &minus));
+    printf ("Result: %d\n", func (&plus, 10, 20));
+    printf ("Result: %d\n", func (&minus, 10, 20));
 
     return EXIT_SUCCESS;
 }