source: CIVL/examples/experimental/oo.c@ 7a13bdf

1.23 2.0 main test-branch
Last change on this file since 7a13bdf was 6a8f071, checked in by Stephen Siegel <siegel@…>, 11 years ago

Adding experimental example oo.c simulating object-oriented code.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@2289 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 475 bytes
Line 
1#include <assert.h>
2
3typedef struct Point {
4 int (*getX)(void);
5 int (*getY)(void);
6 void (*setX)(int);
7 void (*setY)(int);
8} Point;
9
10Point make_point(int x0, int y0) {
11 int x, y;
12
13 int getX() { return x; }
14 int getY() { return y; }
15 void setX( int x1 ) { x=x1; }
16 void setY( int y1 ) { y=y1; }
17
18 Point result = {&getX, &getY, &setX, &setY};
19
20 return result;
21}
22
23int main() {
24 Point p1 = make_point(0,0);
25 Point p2 = make_point(1,2);
26
27 assert(p1.getX()==0);
28}
Note: See TracBrowser for help on using the repository browser.