HP3000-L Archives

May 1999, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Walter Murray <[log in to unmask]>
Reply To:
Date:
Mon, 17 May 1999 22:55:32 GMT
Content-Type:
text/plain
Parts/Attachments:
text/plain (38 lines)
Mark Bixby ([log in to unmask]) wrote:
: Stan Sieler writes:
: > static struct pac16 {
: >  char p[17];
: >  } myvar16 ;

: ...deletia...

: > myvar16 = pascalfunc16 (123);
: > printf ("rslt 16 = %s\n", myvar16.p);

: <NIT>
: Does the C/Pascal calling interface implicitly terminate Pascal PACs with a
: null that C expects as the end-of-string marker?  If not, you'll need to
: manually set myvar16.p[17] to null.
: </NIT>

Just to pick a nit on a nit, but Mark probably meant to say you would
want to set myvar16.p[16] to a null character.  Recall that array
subscripts in C always start with zero.

The important thing is to understand how PACs and strings and arrays
work in both languages, and use a consistent strategy in dealing with
them.  In the changes that I proposed in my earlier post, I chose not
to declare an extra character in the C array, but to use the
%.<precision>s conversion specification to prevent printf() from
accessing too many characters.

And, no, neither language takes care of this for you.  Neither the
caller nor the callee knows that it is communicating with a
procedure written in a different language.  (Although you can
tell a Pascal program that it is calling a C function, and then
it will do some magic on any parameter of type string.)

Walter Murray
Hewlett-Packard
C/iX project

ATOM RSS1 RSS2