Function Pointer Demo simplified
It makes more sense to show the basic usage of fps
committer: Markus Bröker <mbroeker@largo.homelinux.org>
--- 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;
}