Records and structures – HP SunSoft Pascal 4.0 User Manual

Page 170

Advertising
background image

146

Pascal 4.0 User’s Guide

7

Records and Structures

A Pascal record of an integer and a character string matches a C++ structure of
the same constructs, as in this example:

The commands to compile and
execute

DaysOfWeek.p

and

DaysOfWeekMain.cc

without

the

-calign

option

hostname% pc -c DaysOfWeek.p

hostname% CC DaysOfWeek.o DaysOfWeekMain.cc -lpc

hostname% a.out

Day = ''

The commands to compile and
execute

DaysOfWeek.p

and

DaysOfWeekMain.cc

with the

-calign

option

hostname% pc -c -calign DaysOfWeek.p

hostname% CC DaysOfWeek.o DaysOfWeekMain.cc -lpc

hostname% a.out

Day = 'Sunday'

The Pascal procedure,

StruChr.p

. It is safer for the

Pascal procedure to explicitly
provide the null byte and include
it in the count before the string is
passed to C++.

type

TLenStr = record

NBytes: integer;

ChrStr: array [0..24] of char;

end;

procedure StruChr (

var v: TLenStr

);

begin

v.NBytes := 14;

v.ChrStr := 'St.Petersburg' + chr(0);

end;

Advertising