File: runme.c

package info (click to toggle)
swig 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 46,232 kB
  • sloc: cpp: 54,631; ansic: 29,122; java: 17,530; python: 12,505; cs: 10,369; ruby: 7,232; yacc: 6,477; makefile: 5,965; javascript: 5,520; sh: 5,415; perl: 4,187; php: 3,693; ml: 2,187; lisp: 2,056; tcl: 1,991; xml: 115
file content (44 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>

#include "example_wrap.h"

int main(int argc, char **argv) {
  printf("Creating some objects from C:\n");
  Circle* c = Circle_new(10);
  printf("    Created circle\n");
  Square* s = Square_new(10);
  printf("    Created square\n");

  printf("\nA total of %d shapes were created\n", Shape_nshapes_get());

  Circle_x_set(c, 20);
  Circle_y_set(c, 30);

  Shape* shape = (Shape*) s;
  Shape_x_set(shape, -10);
  Shape_y_set(shape, 5);

  printf("\nHere is their current positions:\n");
  printf("    Circle = (%f %f)\n", Circle_x_get(c), Circle_y_get(c));
  printf("    Square = (%f %f)\n", Square_x_get(s), Square_y_get(s));

  printf("\nHere are some properties of the shapes:\n");
  Shape* shapes[] = {(Shape*) c, (Shape*) s};
  int i;
  for (i = 0; i < 2; i++) {
    printf("    %s\n", i ? "Square" : "Circle");
    printf("    area      = %f\n", Shape_area(shapes[i]));
    printf("    perimeter = %f\n", Shape_perimeter(shapes[i]));
  }

  printf("\nGuess I'll clean up now\n");

  Square_delete(s);
  Circle_delete(c);

  printf("%d shapes remain\n", Shape_nshapes_get());
  printf("Goodbye from C\n");

  return 0;
}