6

The commands to compile and execute IntCA.c and IntCAMain.p

hostname% cc -c IntCA.c

hostname% pc -calign IntCA.o IntCAMain.p

hostname% a.out

444

The -calignoption is not needed for this example, but may be necessary if the array parameter is an array of aggregates.

Records and Structures

In most cases, a Pascal record describes the same objects as its C structure equivalent, provided that the components have compatible types and are declared in the same order. For more information, see “Compatibility of Types for C and Pascal” on page 90.

Records that contain aggregates may differ because aggregates in C and Pascal sometimes have different sizes and alignments. If you compile the Pascal code with the -calignoption, the differences are eliminated.

A Pascal record of an integer and a character string matches a C structure of an integer and an array of char values, as follows:

The C function, StruChr.c

#include <string.h>

struct TVarLenStr {

int nbytes; char a[26];

};

void StruChr(struct TVarLenStr *v)

{

strncpy(v->a, "strvar", 6); v->nbytes = 6;

}

124

Pascal 4.0 User’s Guide