Xref: utzoo comp.os.vms:5859 comp.lang.pascal:847 Path: utzoo!mnetor!uunet!husc6!cmcl2!brl-adm!umd5!purdue!i.cc.purdue.edu!j.cc.purdue.edu!pur-ee!iuvax!bsu-cs!cfchiesa From: cfchiesa@bsu-cs.UUCP (Christopher Chiesa) Newsgroups: comp.os.vms,comp.lang.pascal Subject: Re: Quoted string parameters in VAX Pascal? Message-ID: <2812@bsu-cs.UUCP> Date: 29 Apr 88 22:06:32 GMT References: Organization: CS Dept, Ball St U, Muncie, Indiana Lines: 73 Summary: Something to try In article , elkins@elbereth.rutgers.edu (George Elkins) writes: > > Is there a way in VAX Pascal to define a procedure that will take > a variable length quoted string as a parameter? What I would like > to do is imitate the variable length quoted string parameter behavior > of the WRITE and WRITELN procedures, although this is not possible > for user-written procedures in STANDARD Pascal. I want the quoted > string parameter to be within the argument list itself, as in the > WRITELN procedure. I am trying to avoid assigning the string to an > arbitrarily long fixed-length packed array and passing the Pascal > identifier for the array and the integer length of the string. > > Example of what I want to do: > > foo('This is a string of any length'); {User-written procedure foo} > > Examples of what I am avoiding: > > foo(PackedArrayName, StringLength); {Packed array and string length} > or > foo(String.Body, String.Length); {Record with packed array and integer} > > Is this possible or conceivable in VAX Pascal? (I'll admit that I haven't > consulted the documentation. I don't have easy access to it.) > > George Elkins When in doubt, use a RECORD. One hitch with that is that you usually can't pass a RECORD data type as a parameter, but you can get around THAT by pass- ing a POINTER to the record you're after. For variable-length strings, you'll still have to work within SOME maximum- length limit, but in general you'd do something like this: TYPE vstring: ^vrec; vrec: RECORD body : PACKED ARRAY [1..maxstring] OF char; length : INTEGER; END; PROCEDURE FakeWriteln (VAR s: vstring); BEGIN (* Assorted manipulations of the string having body s^.body, of which the first s^.length characters are valid. *) . . . END; Now, it just so happens that the folks at DEC anticipated this, and built in a datatype you may be aware of but haven't mentioned: VARYING [...] OF char; This creates an "implicit record" type, containing the fields "body" and "length" pretty much as I declared 'em above for (semi-) standard Pascal. In Vax Pascal, anyway, "write" and "read" and "writeln" and so on, will oper- ate quite happily on these variable-length strings. You can pass them to system routines, also, using either the "%desc" or "%stdesc" passing-mechanism specifiers (I forget which is for VARYING strings and which is for PACKED strings; try 'em and use whatever works... :-) ) Hope this is of use to you; feel free to e-mail for clarification. Chris Chiesa -- UUCP: !{iuvax,pur-ee,uunet}!bsu-cs!cfchiesa cfchiesa@bsu-cs.UUCP