Listing 3: C translation

//
//    X.h
//
typedef struct X
    {
    int value_;
    } X;

void X_construct_from_int(X *, int);
void X_construct(X *);
void X_destruct(X *);
void X_assign(X *, X const *);
int X_to_int(X const *);
int X_count();

//
//    X.c
//
#include "X.h"

static int count_ = 0;

void X_construct_from_int(X *const this, int value)
    {
    this->value_ = value;
    ++count_;
    }

void X_construct(X *const this)
    {
    X_construct_from_int(this, 10);
    }

void X_destruct(X *const this)
    {
    --count_;
    }

void X_assign(X *const this, X const *const that)
    {
    this->value_ = that->value_;
    }

int X_to_int(X const *const this)
    {
    return this->value_;
    }

int X_count()
    {
    return count_;
    }

//
//    main.c
//
#include <stdio.h>
#include "X.h"

int main(void)
    {
    printf("count is %d\n\n", X_count());
    /* block */
        {
        X x1;
        X x2;
        X_construct(&x1);
        X_construct_from_int(&x2, 20);
        printf("count is %d\n\n", X_count());
        printf("x1 is %d\n", X_to_int(&x1));
        printf("x2 is %d\n\n", X_to_int(&x2));
        X_assign(&x1, &x2);
        printf("x1 is %d\n\n", X_to_int(&x1));
        X_destruct(&x2);
        X_destruct(&x1);
        }
    printf("count is %d\n", X_count());
    return 0;
    }
— End of Listing —