/* StdCCorpse2.c */ #define NULL 0 extern char *malloc(); extern void Croak(); struct _node { int val; struct _node *left, *right}; typedef struct _node *tree; struct _object { void *private; int *pval; tree (*insert)(/* self, val */); tree (*seek)(/* self, val */); }; typedef struct _object *object; tree TreeInsert(t, val) tree t; int val; { if (t == NULL) { t = (tree) malloc(sizeof(struct _node)); t->val = val; t->left = t->right = NULL; } else if (t->val < val) t->right = TreeInsert(t->right, val); else if (t->val > val) t->left = TreeInsert(t->left, val); if (val == 15) Croak(); return t; } tree ObjectInsert(self, val) object self; int val; { tree t = (tree) self->private; tree u; u = TreeInsert(t, val); self->pval = &(u->val); self->private = u; return u; } extern StdCCorpse2Test () { object o = (object) malloc(sizeof(struct _object)); o->private = NULL; o->insert = ObjectInsert; o->seek = ObjectInsert; o->insert(o, 10); o->seek(o, 5); (*o->insert)(o, 15); return; }