1 /* File : example.c */
2
3 /* I'm a file containing some C global variables */
4
5 /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
6 #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
7 # define _CRT_SECURE_NO_DEPRECATE
8 #endif
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include "example.h"
13
14 int ivar = 0;
15 short svar = 0;
16 long lvar = 0;
17 unsigned int uivar = 0;
18 unsigned short usvar = 0;
19 unsigned long ulvar = 0;
20 signed char scvar = 0;
21 unsigned char ucvar = 0;
22 char cvar = 0;
23 float fvar = 0;
24 double dvar = 0;
25 char *strvar = 0;
26 #ifdef __cplusplus // Note: for v8 this must be linkable with g++, without extern cstrvar is mangled
27 extern const char cstrvar[] = "Goodbye";
28 #else
29 const char cstrvar[] = "Goodbye";
30 #endif
31 const
32 int *iptrvar = 0;
33 char name[256] = "Dave";
34 char path[256] = "/home/beazley";
35
36
37 /* Global variables involving a structure */
38 Point *ptptr = 0;
39 Point pt = { 10, 20 };
40
41 /* A variable that we will make read-only in the interface */
42 int status = 1;
43
44 /* A debugging function to print out their values */
45
print_vars()46 void print_vars() {
47 printf("ivar = %d\n", ivar);
48 printf("svar = %d\n", svar);
49 printf("lvar = %ld\n", lvar);
50 printf("uivar = %u\n", uivar);
51 printf("usvar = %u\n", usvar);
52 printf("ulvar = %lu\n", ulvar);
53 printf("scvar = %d\n", scvar);
54 printf("ucvar = %u\n", ucvar);
55 printf("fvar = %g\n", fvar);
56 printf("dvar = %g\n", dvar);
57 printf("cvar = %c\n", cvar);
58 printf("strvar = %s\n", strvar ? strvar : "(null)");
59 printf("cstrvar = %s\n", cstrvar);
60 printf("iptrvar = %p\n", (void *)iptrvar);
61 printf("name = %s\n", name);
62 printf("ptptr = %p (%d, %d)\n", (void *)ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
63 printf("pt = (%d, %d)\n", pt.x, pt.y);
64 printf("status = %d\n", status);
65 }
66
67 /* A function to create an integer (to test iptrvar) */
68
new_int(int value)69 int *new_int(int value) {
70 int *ip = (int *) malloc(sizeof(int));
71 *ip = value;
72 return ip;
73 }
74
75 /* A function to create a point */
76
new_Point(int x,int y)77 Point *new_Point(int x, int y) {
78 Point *p = (Point *) malloc(sizeof(Point));
79 p->x = x;
80 p->y = y;
81 return p;
82 }
83
Point_print(Point * p)84 char * Point_print(Point *p) {
85 static char buffer[256];
86 if (p) {
87 sprintf(buffer,"(%d,%d)", p->x,p->y);
88 } else {
89 sprintf(buffer,"null");
90 }
91 return buffer;
92 }
93
pt_print()94 void pt_print() {
95 printf("(%d, %d)\n", pt.x, pt.y);
96 }
97