1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include "frog.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
struct Frog {
const char *name;
int ncroaks;
};
Frog *Frog_new(const char *name) {
Frog *self = malloc(sizeof *self);
assert(self);
self->name = name;
self->ncroaks = 0;
return self;
}
void Frog_free(Frog *self) {
assert(self);
free(self);
}
static void Frog_croak(VSelf) {
VSELF(Frog);
printf("%s: croak!\n", self->name);
self->ncroaks++;
}
implExtern(Croak, Frog);
|