PageRenderTime 30ms CodeModel.GetById 25ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 1ms

/tags/rel-1-3-26/SWIG/Examples/lua/variables/example.c

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