/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>

struct A
{
   int va;
   void (*f1)(struct A *a);
};

struct B
{
   int va;
   void (*f1)(struct A *a);
   int vb;
};

void constructorA(struct A *a)
{
    a->va = 123;
    a->f1 = NULL;
}

void f1B(struct A *a);

void constructorB(struct B *b)
{
    constructorA((struct A *)b);
    b->f1 = f1B; 
    b->vb = 456;
}

void f1B(struct A *a)
{
    printf("%d\n",a->va);
}

void f2(struct B *b)
{
    printf("%d\n",b->vb);
}

int main()
{
    struct B *b = (struct B *)malloc(sizeof(struct B));
    constructorB(b);
    b->f1((struct A *)b);
    f2(b);
    free(b);
    return 0;
}
