Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 41 lines (35 sloc) 0.928 kB
2a01379 @arnsholt Preliminary tests for structs and CArray members.
arnsholt authored
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #ifdef WIN32
6 #define DLLEXPORT __declspec(dllexport)
7 #else
8 #define DLLEXPORT extern
9 #endif
10
11 typedef struct {
8490818 @arnsholt Some struct test updates.
arnsholt authored
12 long intval;
2a01379 @arnsholt Preliminary tests for structs and CArray members.
arnsholt authored
13 double numval;
8490818 @arnsholt Some struct test updates.
arnsholt authored
14 long *arr;
2a01379 @arnsholt Preliminary tests for structs and CArray members.
arnsholt authored
15 } MyStruct;
16
17 DLLEXPORT MyStruct *ReturnAStruct()
18 {
19 MyStruct *obj = (MyStruct *) malloc(sizeof(MyStruct));
20 obj->intval = 17;
21 obj->numval = 4.2;
8490818 @arnsholt Some struct test updates.
arnsholt authored
22 obj->arr = (long *) malloc(3*sizeof(long));
2a01379 @arnsholt Preliminary tests for structs and CArray members.
arnsholt authored
23 obj->arr[0] = 2;
24 obj->arr[1] = 3;
25 obj->arr[2] = 5;
26
27 return obj;
28 }
29
30 DLLEXPORT void TakeAStruct(MyStruct *obj)
31 {
32 if(obj->intval != 42) printf("not ");
33 printf("ok - C-side int value\n");
34 if(obj->numval != -3.7) printf("not ");
35 printf("ok - C-side num value\n");
36 if(!obj->arr || obj->arr[0] != 1) printf("not ");
37 printf("ok - C-side array value, element 1\n");
38 if(!obj->arr || obj->arr[1] != 2) printf("not ");
39 printf("ok - C-side array value, element 2\n");
40 }
Something went wrong with that request. Please try again.