106
Pascal 4.0 User’s Guide
6
The record in the example above has, by default, the same size and alignment
as the equivalent C record. Some records, though, are laid out differently
unless you use the
-calign
option.
The C main program,
StruChrMain.c
#include <stdio.h>
#include <string.h>
struct TVarLenStr {
int NBytes;
char a[25];
};
extern void StruChr(struct TVarLenStr *);
int main(void)
{
struct TVarLenStr vls;
char s25[25];
vls.NBytes = 0;
StruChr(&vls);
strncpy(s25, vls.a, vls.NBytes);
printf(" s25 = '%s' \n", s25);
printf(" strlen(s25) = %d \n", strlen(s25));
}
The commands to compile and
execute
StruChr.p
and
StruChrMain.c
hostname% pc -c StruChr.p
hostname% cc StruChr.o StruChrMain.c -lpc
hostname% a.out
s25='St. Petersburg'
strlen(s25) = 13
Содержание SunSoft Pascal 4.0
Страница 14: ...xiv Pascal 4 0 User s Guide ...
Страница 16: ...xvi Pascal 4 0 User s Guide ...
Страница 30: ...6 Pascal 4 0 User s Guide 1 ...
Страница 160: ...136 Pascal 4 0 User s Guide 6 ...
Страница 268: ...244 Pascal 4 0 User s Guide 11 ...
Страница 320: ...296 Pascal 4 0 User s Guide B ...
Страница 331: ...Index 307 ...
Страница 333: ......