summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-05-23 00:27:50 +0200
committerTyge Løvset <[email protected]>2022-05-23 00:27:50 +0200
commit9284ac7695cb664e480b8b5962005c5a2bf9b3a3 (patch)
tree089a3e193274c7773c4b943f8ae825b876c9ba35 /examples
parent1c3e7b683469904d224f3f8f1ee0096f1c5b1b9d (diff)
downloadSTC-modified-9284ac7695cb664e480b8b5962005c5a2bf9b3a3.tar.gz
STC-modified-9284ac7695cb664e480b8b5962005c5a2bf9b3a3.zip
Small shape.c update.
Diffstat (limited to 'examples')
-rw-r--r--examples/shape.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/examples/shape.c b/examples/shape.c
index 04aecaa1..d3534021 100644
--- a/examples/shape.c
+++ b/examples/shape.c
@@ -4,10 +4,8 @@
#include <stdio.h>
#include <stc/ccommon.h>
-#define c_self(s, T) \
- T* self = (T *)(s); \
- assert(&T##_api == (s)->api && \
- &T##_api == self->base.api)
+#define c_dyn_ptr(T, s) \
+ (&T##_api == (s)->api ? (T*)(s) : (T*)0)
#define c_vtable(Api, T) \
c_static_assert(offsetof(T, base) == 0); \
@@ -66,7 +64,7 @@ Triangle* Triangle_new(Point a, Point b, Point c)
static void Triangle_draw(const Shape* shape)
{
- const c_self(shape, Triangle);
+ const Triangle* self = c_dyn_ptr(Triangle, shape);
printf("Triangle : (%g,%g), (%g,%g), (%g,%g)\n",
self->p[0].x, self->p[0].y,
self->p[1].x, self->p[1].y,
@@ -105,7 +103,7 @@ void Polygon_addPoint(Polygon* self, Point p)
static void Polygon_drop(Shape* shape)
{
- c_self(shape, Polygon);
+ Polygon* self = c_dyn_ptr(Polygon, shape);
printf("poly destructed\n");
PointVec_drop(&self->points);
Shape_drop(shape);
@@ -113,7 +111,7 @@ static void Polygon_drop(Shape* shape)
static void Polygon_draw(const Shape* shape)
{
- const c_self(shape, Polygon);
+ const Polygon* self = c_dyn_ptr(Polygon, shape);
printf("Polygon :");
c_foreach (i, PointVec, self->points)
printf(" (%g,%g)", i.ref->x, i.ref->y);