comp.lang.ada
 help / color / mirror / Atom feed
From: cis.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!noc.near.ne t!inmet!panther.warm.inmet.com!brennan@ucbvax.Berkeley.EDU  (William Brennan)
Subject: Re: How to assign STRINGs?
Date: 27 Aug 93 15:35:04 GMT	[thread overview]
Message-ID: <1993Aug27.153504.1340@warm.inmet.com> (raw)

In article <1993Aug25.121754.20413@hellgate.utah.edu> matwood%peruvian.cs.utah.
edu@cs.utah.edu (Mark Atwood) writes:

>So, how DO i assign the results of a function returning an unconstrained
>string to a constrained string?

Here's a solution I've found useful.  It relies on the fact that an 
unconstrained array can be constrained when the memory is allocated for
an access pointer (i.e., at run time).
It has the advantage of maintaining a string of the correct length, containing 
only the characters which are real (avoiding pad characters).
It has the disadvantage of using dynamic memory.

with Text_IO;
with Unchecked_Deallocation;
procedure ECHO is
  type String_Ptr_Type is access String;
  procedure Dispose is new Unchecked_Deallocation( String, String_Ptr_Type );
  CMDLINE_PTR: String_Ptr_Type;
begin
  CMDLINE_PTR := new String'(DOS.GET_PARMS);
  Text_IO.Put_Line( CMDLINE_PTR.all );
  ... other work with CMDLINE_PTR ... 
  Dispose( CMDLINE_PTR );
end ECHO;

             reply	other threads:[~1993-08-27 15:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-08-27 15:35 cis.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!noc.near.ne [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-09-07 21:56 How to assign STRINGs? Robert I. Eachus
1993-09-03 18:18 dog.ee.lbl.gov!overload.lbl.gov!agate!doc.ic.ac.uk!uknet!mcsun!ub4b!cfmu!
1993-08-27 20:23 Robert I. Eachus
1993-08-27 19:00 Tucker Taft
1993-08-26 18:17 cis.ohio-state.edu!pacific.mps.ohio-state.edu!math.ohio-state.edu!howland
1993-08-26 16:54 cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland.
1993-08-26 14:09 Joe Hildebrand
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox