PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/go/variables/example.c

#
C | 91 lines | 68 code | 15 blank | 8 comment | 3 complexity | 214e6e93cf584e168880be76db22ac90 MD5 | raw file
 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
14int              ivar = 0;                    
15short            svar = 0;
16long             lvar = 0;
17unsigned int     uivar = 0;
18unsigned short   usvar = 0;
19unsigned long    ulvar = 0;
20signed char      scvar = 0;
21unsigned char    ucvar = 0;
22char             cvar = 0;
23float            fvar = 0;
24double           dvar = 0;
25char            *strvar = 0;
26const char       cstrvar[] = "Goodbye";
27int             *iptrvar = 0;
28char             name[256] = "Dave";
29char             path[256] = "/home/beazley";
30
31
32/* Global variables involving a structure */
33Point           *ptptr = 0;
34Point            pt = { 10, 20 };
35
36/* A variable that we will make read-only in the interface */
37int              status = 1;
38
39/* A debugging function to print out their values */
40
41void print_vars() {
42  printf("ivar      = %d\n", ivar);
43  printf("svar      = %d\n", svar);
44  printf("lvar      = %ld\n", lvar);
45  printf("uivar     = %u\n", uivar);
46  printf("usvar     = %u\n", usvar);
47  printf("ulvar     = %lu\n", ulvar);
48  printf("scvar     = %d\n", scvar);
49  printf("ucvar     = %u\n", ucvar);
50  printf("fvar      = %g\n", fvar);
51  printf("dvar      = %g\n", dvar);
52  printf("cvar      = %c\n", cvar);
53  printf("strvar    = %s\n", strvar ? strvar : "(null)");
54  printf("cstrvar   = %s\n", cstrvar ? cstrvar : "(null)");
55  printf("iptrvar   = %p\n", iptrvar);
56  printf("name      = %s\n", name);
57  printf("ptptr     = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
58  printf("pt        = (%d, %d)\n", pt.x, pt.y);
59  printf("status    = %d\n", status);
60}
61
62/* A function to create an integer (to test iptrvar) */
63
64int *new_int(int value) {
65  int *ip = (int *) malloc(sizeof(int));
66  *ip = value;
67  return ip;
68}
69
70/* A function to create a point */
71
72Point *new_Point(int x, int y) {
73  Point *p = (Point *) malloc(sizeof(Point));
74  p->x = x;
75  p->y = y;
76  return p;
77}
78
79char * Point_print(Point *p) {
80  static char buffer[256];
81  if (p) {
82    sprintf(buffer,"(%d,%d)", p->x,p->y);
83  } else {
84    sprintf(buffer,"null");
85  }
86  return buffer;
87}
88
89void pt_print() {
90  printf("(%d, %d)\n", pt.x, pt.y);
91}