[comp.lang.pascal] Defining variable lenght arraysSKIP

g_harrison@vger.nsu.edu (10/17/90)

In article <16401@shlump.nac.dec.com>, mailman@telfon.enet.dec.com (Steven M. Mailman) writes:
> In article <24785@adm.BRL.MIL>, BESKO%MSUNSCL.BITNET@uga.cc.uga.edu writes...
>> 
>>Does anyone know if it is possible and how to define a variable length char
>>array in VAX Pascal?  Any information would be helpful.
>> 
> There are multiple ways.  The 2nd & 3rd are new in VAX Pascal V4.0.
> 
> {1}	{ variable length text; max size of 80 characters }
> 	VAR
> 	    x : VARYING [80] OF Char;

This I know about, bot these are really neat!!

> {2}	{ regular PACKED ARRAY of Char but length is specified at run-time }
> 	TYPE
> 	   pac( Length:Integer ) = PACKED ARRAY [1..Length] OF Char;
> 	VAR
> 	    x : pac(run-time-expression);
> 	x := 'text';		{text is blank padded to correct size}
> 	Writeln( x.length );	{prints length captured in declaration}
> 
> {3}	{ variable length text with max length specified at run-time }
> 	VAR
> 	    x : String(run-time-expression);
> 	x := 'text';
> 	Writeln( x.length );    {prints 4}
> 	Writeln( x.capacity );	{prints max-size captured in declaration}
> 
> 
> Steve Mailman
> Digital Equipment Corporation
> mailman@tle.enet.dec.com
> Disclaimer:  The opinions and statements expressed by me are not
>              necessarily those of Digital Equipment Corporation.

Does #2 work with any type of packed array?  For example the critical thing
with variable length arrays is to use them at run time for different types like
in Ada.  Having INT_PAC (SIZE : INTEGER) = packed array [1..SIZE] of INTEGER;
and var M : INT_PAC(5);
        N : INT_PAC(199);
would sure be handy.

The problem as I see it is that these arrays are of the same implementation
size anyway; is that right?  In other words they are structurally the same -
blanking out unneeded storage areas but still having that storage area
"charged" to the program.

However, the features are indeed nice.  Thanks for the reply.

George...
--------------------------------------------------------------------------
-- George C. Harrison                 INTERNET: g_harrison@vger.nsu.EDU --
-- Professor of Computer Science               Subliminal Address:  adA --
-- Norfolk State University                                             --
--   The views expressed here are not necessarily those of              --
--   the Univesity, my wife, or my children.                            --
--------------------------------------------------------------------------