From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 26 Aug 93 16:54:24 GMT From: cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland. reston.ans.net!vixen.cso.uiuc.edu!cs.uiuc.edu!cs.uiuc.edu!rowe@ucbvax.Berkeley. EDU (Kenneth E. Rowe) Subject: Re: How to assign STRINGs? Message-ID: List-Id: In article <1993Aug25.121754.20413@hellgate.utah.edu> matwood%peruvian.cs.utah. edu@cs.utah.edu (Mark Atwood) writes: > >I'm kind of embarrassed asking this, after using Ada for over a year, but >I was never very clear on unconstrained arrays, and now it's bitten me. > >Here is some representative code. > > > function GET_PARM return STRING; > -- from the vendor supplied DOS package > > with TEXT_IO; > procedure ECHO is > subtype STR is STRING(1 .. 255); > CMDLINE : STR; > begin > CMDLINE := DOS.GET_PARMS; -- get a CONTRAINT_ERROR here > TEXT_IO.PUT_LINE (CMDLINE); > end ECHO; > > >So, how DO i assign the results of a function returning an unconstrained >string to a constrained string? > >-- >Mark Atwood | My school and employer have too many problems >matwood@peruvian.cs.utah.edu | without being blamed for mine. have you tried CMDLINE (1..255) := Dos.Get_Parms; ??? if so then you can use the text_io routines that use a string as input and pars es it out. Unfortunately, all the "normal" tricks with array slices doesn't work when a function has side effects (2 calls in a row give different results). normally you can just do: cmdline(1..(dos.get_parms)'length) := dos.get_parms; **** but ONLY if dos.get_parms doesn't change between the two calls. Hopefully there is just an over-sight in the documentation on dos.get_parms. Try the first example and see what happens. Ken.