Upstream version 1.3.40
[profile/ivi/swig.git] / Examples / test-suite / funcptr.i
1 %module funcptr
2
3 /*
4  Complicated one that should defeat just reading , to find
5  the number of arguments expected in the function pointer.
6 extern void do(int (*op)(int (*i)(double, double), int j)); 
7 */
8
9 %inline %{
10 typedef double (*DistFun)(double* data, int r, int c, int i, int j, void *xdata);
11
12 void distance(double *data, int *dim, DistFun fun,  double *output) {
13 }
14
15 typedef int (*Operator)(int i,int j);
16
17 int do_op(int a, int b, int (*op)(int,int)) {
18   return (*op)(a,b);
19 }
20
21 int add(int a, int b) {
22   return a+b;
23 }
24
25 int subtract(int a, int b) {
26   return a-b;
27 }
28
29 int multiply(int a, int b) {
30   return a*b;
31 }
32
33 int *nowt() { 
34   return 0;
35 }
36
37 int *nowt2(void) { 
38   return 0;
39 }
40
41 struct MyStruct { int i; };
42 typedef struct MyStruct * MyStructPtr;
43
44 MyStructPtr mystructptr() { 
45   return 0;
46 }
47
48 typedef int * Integer;
49
50 int (*funcvar)(int,int) = add;
51 int * (*funcvar2)() = nowt;
52 int * (*funcvar3)(void) = nowt2;
53 Integer (*funcvar4)() = nowt;
54 MyStructPtr (*funcvar5)() = mystructptr;
55
56 void (*pfunc0)();
57 int (*pfuncA)();
58 void (*pfunc1)(int);
59 void (*pfunc2)(int, double);
60 %}