BESKO%MSUNSCL.BITNET@uga.cc.uga.edu (10/16/90)
Does anyone know if it is possible and how to define a variable length char array in VAX Pascal? Any information would be helpful. Thanks, Lisa Besko
ts@uwasa.fi (Timo Salmi) (10/16/90)
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. In a way, yes. It is called an array of "varying of char type". But this is an array of variable length of chars, not a variable array of variable chars. For more details I'll have to refer you the Programming in Vax Pascal manual. ................................................................... Prof. Timo Salmi (Moderating at anon. ftp site 128.214.12.3) School of Business Studies, University of Vaasa, SF-65101, Finland Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun
mailman@telfon.enet.dec.com (Steven M. Mailman) (10/16/90)
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; x := 'text'; Writeln( x.length ); {prints 4} {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.
lanmaint@nssdca.gsfc.nasa.gov (Dave Yoest) (10/17/90)
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. > >Thanks, > >Lisa Besko Lisa, Yes it's possible.... declare the array of characters as: your_array_name : varying[255] of char; for a varying length char array of 255 char. of course, the variable allocates space for all 255, but "varying" can be assigned to other "varying" array sizes without type mismatches.
ECOAV%ECOSTAT.AAU.DK@uga.cc.uga.edu (10/18/90)
> Does anyone know if it is possible and how to define a variable length char > array in VAX Pascal? Any information would be helpful. Yes - it is possible. Try: var vstr : varying [80] of char; There exist LENGTH,INDEX and SUBSTR functions, and '+' is used as a concatanation operator. Arne Vajhxj ECOAV@ECOSTAT.AAU.DK
mailman@telfon.enet.dec.com (Steven M. Mailman) (10/18/90)
In article <73.271bf8b4@vger.nsu.edu>, g_harrison@vger.nsu.edu writes... >> {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} > >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? No. > 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. > #2 works with any type of ARRAY (packed or unpacked) with any type of component. When using schema types the compiler generates code to compute the size of the array at run-time and then allocates just enough space. Sizes end up getting rounded up to the next byte and some alignment takes place so afew bytes may get wasted. So INT_PA(5) would cause 20 bytes to be allocated on the stack, INT_PA(199) would cause 199*4=796 bytes to be allocated. Some additional information: In the #2 example above, the resulting schematic pac (packed array of char) behaves just like a regular pac except the size of the array is determined at run-time. In the #3 example, the schema type STRING is predefined as TYPE STRING(Capacity:1..65535) = VARYING [Capacity] OF Char; A schema type by it self is incomplete because it has no size information. You can't say VAR v : String; To create a variable of a schema type, you have to discriminate the schema. The values in parens are called actual discriminants VAR v : String(200); There are two places when an undiscriminated schema can be used: For a pointer base type: VAR p : ^String; NEW(p,200); { supply actual discriminants in NEW} And as the type of a parameter: PROCEDURE x( v : String ); {accept any size string} ------ 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.