Skip to content
This repository
Newer
Older
100644 62 lines (52 sloc) 1.381 kb
f2f21b1f »
2012-01-13 Tests for passing/returning array of doubles.
1 #include <stdio.h>
2 #include <stdlib.h>
ecf0ae46 » moritz
2012-01-16 get rid of a GCC warning
3 #include <string.h>
f2f21b1f »
2012-01-13 Tests for passing/returning array of doubles.
4
5 #ifdef WIN32
6 #define DLLEXPORT __declspec(dllexport)
7 #else
8 #define DLLEXPORT extern
9 #endif
10
11 DLLEXPORT double * ReturnADoubleArray()
12 {
13 double *foo = malloc(3 * sizeof(double));
14 foo[0] = 23.45;
15 foo[1] = -99.87;
16 foo[2] = 0.25;
17 return foo;
18 }
19
20 DLLEXPORT double TakeADoubleArrayAndAddElements(double *arr)
21 {
22 return arr[0] + arr[1];
23 }
24
25 DLLEXPORT char ** ReturnAStringArray()
26 {
27 char **foo = malloc(2 * sizeof(char *));
28 foo[0] = "La Trappe";
29 foo[1] = "Leffe";
30 return foo;
31 }
32
33 DLLEXPORT int TakeAStringArrayAndReturnTotalLength(char **arr)
34 {
6437bbb8 »
2012-01-13 Tests for passing and returning arrays of strings.
35 return (int)(strlen(arr[0]) + strlen(arr[1]));
f2f21b1f »
2012-01-13 Tests for passing/returning array of doubles.
36 }
c9d7e10b » arnsholt
2012-04-22 Tests for objects in CArrays.
37
38 typedef struct {
39 long value;
40 } Struct;
41
42 DLLEXPORT Struct **ReturnAStructArray() {
43 Struct **arr = (Struct **) malloc(3*sizeof(Struct *));
44 arr[0] = malloc(sizeof(Struct));
45 arr[1] = malloc(sizeof(Struct));
46 arr[2] = malloc(sizeof(Struct));
47
48 arr[0]->value = 2;
49 arr[1]->value = 3;
50 arr[2]->value = 5;
51
52 return arr;
53 }
54
55 DLLEXPORT void TakeAStructArray(Struct **structs) {
56 if(structs[0]->value != 7) printf("not ");
9dde6098 » moritz
2012-04-23 do not print test numbers from C, more flexible that way
57 printf("ok - struct in position 0, C-side\n");
c9d7e10b » arnsholt
2012-04-22 Tests for objects in CArrays.
58 if(structs[1]->value != 11) printf("not ");
9dde6098 » moritz
2012-04-23 do not print test numbers from C, more flexible that way
59 printf("ok - struct in position 1, C-side\n");
c9d7e10b » arnsholt
2012-04-22 Tests for objects in CArrays.
60 if(structs[2]->value != 13) printf("not ");
9dde6098 » moritz
2012-04-23 do not print test numbers from C, more flexible that way
61 printf("ok - struct in position 2, C-side\n");
c9d7e10b » arnsholt
2012-04-22 Tests for objects in CArrays.
62 }
Something went wrong with that request. Please try again.