Simple types with –xl, Strings of characters – HP SunSoft Pascal 4.0 User Manual

Page 120

Advertising
background image

96

Pascal 4.0 User’s Guide

6

Simple Types with

–xl

With the

-xl

option, the Pascal

real

must be paired with a C

float

, and the

Pascal

integer

must be paired with a C

short int

.

Strings of Characters

The C counterpart to the Pascal

alfa

and

string

types are arrays; C passes

all arrays by reference. The C counterpart to the Pascal

varying

is a structure;

C passes structures by value.

Before you call Pascal with a null varying string, set the byte count to zero
because that is what Pascal assumes about such strings.

C can pass a structure consisting of a four-byte integer and an array of
characters to a Pascal procedure, expecting a

var

parameter that is a variable-

length string.

See the following example:

The commands to compile and
execute

SimVar.p

and

SimVarMain.c

hostname% pc -c SimVar.p

hostname% cc SimVar.o SimVarMain.c

hostname% a.out

00000001 00000000 z 9 9 9.9 9.9

The Pascal procedure,

StrVar.p

type

TVarStr = varying [25] of char;

procedure StrVar(

var a: alfa;

var s: string;

var v: TVarStr);

begin

a := 'abcdefghi' + chr(0);

s := 'abcdefghijklmnopqrstuvwxyz' + chr(0);

v := 'varstr' + chr(0);

end; { StrVar }

Advertising