diff options
| author | Tyge Løvset <[email protected]> | 2022-06-20 00:08:18 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-06-20 00:08:18 +0200 |
| commit | 4343af3ad34b71adf668d8e7e68d8d45a04f9f87 (patch) | |
| tree | 4ca4e6b09a8e3f87afddde80923ad4b0368d026d /examples/shape.c | |
| parent | 755bcee8a97b2912d047895d37f5b60672486144 (diff) | |
| download | STC-modified-4343af3ad34b71adf668d8e7e68d8d45a04f9f87.tar.gz STC-modified-4343af3ad34b71adf668d8e7e68d8d45a04f9f87.zip | |
Small addition and warning removed in cregex.c. Else refactoring/cleanup.
Diffstat (limited to 'examples/shape.c')
| -rw-r--r-- | examples/shape.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/examples/shape.c b/examples/shape.c index e5ac0e58..b052d921 100644 --- a/examples/shape.c +++ b/examples/shape.c @@ -7,14 +7,14 @@ #define c_dyn_cast(T, s) \ (&T##_api == (s)->api ? (T*)(s) : (T*)0) -#define c_vtable(Api, T) \ +#define c_vtable(Api, T, base) \ c_static_assert(offsetof(T, base) == 0); \ static Api T##_api // Shape definition // ============================================================ -typedef struct { +typedef struct { float x, y; } Point; @@ -35,7 +35,7 @@ struct Shape { void Shape_drop(Shape* shape) { - printf("base destructed\n"); + printf("shape destructed\n"); } void Shape_delete(Shape* shape) @@ -50,11 +50,11 @@ void Shape_delete(Shape* shape) // ============================================================ typedef struct { - Shape base; + Shape shape; Point p[3]; } Triangle; -c_vtable(struct ShapeAPI, Triangle); +c_vtable(struct ShapeAPI, Triangle, shape); Triangle* Triangle_new(Point a, Point b, Point c) @@ -84,11 +84,11 @@ static struct ShapeAPI Triangle_api = { #include <stc/cstack.h> typedef struct { - Shape base; + Shape shape; PointVec points; } Polygon; -c_vtable(struct ShapeAPI, Polygon); +c_vtable(struct ShapeAPI, Polygon, shape); Polygon* Polygon_new(void) @@ -151,9 +151,9 @@ int main(void) c_apply(p, Polygon_addPoint(pol2, *p), Point, {{5, 7}, {12, 7}, {12, 20}, {82, 33}, {17, 56}}); - Shapes_push(&shapes, &tri1->base); - Shapes_push(&shapes, &pol1->base); - Shapes_push(&shapes, &pol2->base); + Shapes_push(&shapes, &tri1->shape); + Shapes_push(&shapes, &pol1->shape); + Shapes_push(&shapes, &pol2->shape); c_foreach (i, Shapes, shapes) testShape(*i.ref); |
