/* 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; }