6

The C main program,

#include <stdio.h>

VarRecMain.c

 

 

struct vlr {

 

char tag;

 

union {

 

struct {

 

char ch1, ch2;

 

}a_var;

 

struct {

 

char flag;

 

}b_var;

 

struct {

 

int ALIGN;

 

}c_var;

 

}var_part;

 

};

 

extern void VarRec(struct vlr *);

 

int main(void)

 

{

 

struct vlr *x;

 

x = (struct vlr *)malloc(sizeof(struct vlr));

 

x->tag = 'a';

 

x->var_part.a_var.ch1 = 'a';

 

x->var_part.a_var.ch2 = 'b';

 

VarRec(x);

 

printf(" %c \n", x->var_part.a_var.ch2);

 

}

 

 

The commands to compile and execute VarRec.p and VarRecMain.c

hostname% pc -c -calign VarRec.p hostname% cc VarRec.o VarRecMain.c -lpc hostname% a.out

Z

The C–Pascal Interface

109