function_pointers.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Tue, 12 May 2009 12:06:26 +0200
changeset 91 1181deef3bd6
parent 77 49e0babccb23
child 103 be3fe4a4f097
permissions -rw-r--r--
fixed a typo in mem2swap.c committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
/**
77
49e0babccb23 HEADER TAGS
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 27
diff changeset
     2
 * function_pointers.c
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     3
 * Copyright (C) 2008 Markus Broeker
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     4
 */
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
#include <stdio.h>
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
#include <stdlib.h>
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     9
typedef struct T {
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    10
    int a;
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    11
    int b;
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
} T;
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    13
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    14
int plus (T t)
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    15
{
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    16
    return t.a + t.b;
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    17
}
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    18
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    19
int minus (T t)
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    20
{
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    21
    return t.a - t.b;
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    22
}
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    23
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    24
int func (T t, int (*ptrFunc) (T))
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    25
{
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    26
    return ptrFunc (t);
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    27
}
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    28
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    29
int main (int argc, char **argv)
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    30
{
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    31
    T t = {
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    32
        .a = 20,
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    33
        .b = 10
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    34
    };
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    36
    printf ("Result: %d\n", func (t, &plus));
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    37
    printf ("Result: %d\n", func (t, &minus));
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    38
27
81a574d60c15 typo in min2time format string
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 24
diff changeset
    39
    return EXIT_SUCCESS;
24
9cdad6c45b47 function pointer demo added
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    40
}