Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 63 lines (52 sloc) 1.381 kb
f2f21b1 Jonathan Worthington Tests for passing/returning array of doubles.
authored
1 #include <stdio.h>
2 #include <stdlib.h>
ecf0ae4 Moritz Lenz get rid of a GCC warning
moritz authored
3 #include <string.h>
f2f21b1 Jonathan Worthington Tests for passing/returning array of doubles.
authored
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 {
6437bbb Jonathan Worthington Tests for passing and returning arrays of strings.
authored
35 return (int)(strlen(arr[0]) + strlen(arr[1]));
f2f21b1 Jonathan Worthington Tests for passing/returning array of doubles.
authored
36 }
c9d7e10 Arne Skjærholt Tests for objects in CArrays.
arnsholt authored
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 ");
9dde609 Moritz Lenz do not print test numbers from C, more flexible that way
moritz authored
57 printf("ok - struct in position 0, C-side\n");
c9d7e10 Arne Skjærholt Tests for objects in CArrays.
arnsholt authored
58 if(structs[1]->value != 11) printf("not ");
9dde609 Moritz Lenz do not print test numbers from C, more flexible that way
moritz authored
59 printf("ok - struct in position 1, C-side\n");
c9d7e10 Arne Skjærholt Tests for objects in CArrays.
arnsholt authored
60 if(structs[2]->value != 13) printf("not ");
9dde609 Moritz Lenz do not print test numbers from C, more flexible that way
moritz authored
61 printf("ok - struct in position 2, C-side\n");
c9d7e10 Arne Skjærholt Tests for objects in CArrays.
arnsholt authored
62 }
Something went wrong with that request. Please try again.