124
Pascal 4.0 User’s Guide
6
The
-calign
option 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
-calign
option, 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 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
4
4
4
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;
}
Summary of Contents for SunSoft Pascal 4.0
Page 14: ...xiv Pascal 4 0 User s Guide ...
Page 16: ...xvi Pascal 4 0 User s Guide ...
Page 30: ...6 Pascal 4 0 User s Guide 1 ...
Page 160: ...136 Pascal 4 0 User s Guide 6 ...
Page 268: ...244 Pascal 4 0 User s Guide 11 ...
Page 320: ...296 Pascal 4 0 User s Guide B ...
Page 331: ...Index 307 ...
Page 333: ......