comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: [Q] Returning Strings From A Function
Date: 1997/04/05
Date: 1997-04-05T00:00:00+00:00	[thread overview]
Message-ID: <E86IKy.In2@world.std.com> (raw)
In-Reply-To: 33468b81.762963@news.demon.co.uk


In article <33468b81.762963@news.demon.co.uk>,
John McCabe <john@assen.demon.co.uk> wrote:
>   File_Name : constant string := Text_IO.Name (File);

I don't remember if you were specifically asking about Ada 83, but Ada
95 also allows:

    File_Name : String := Text_IO.Name (File);

which allows you to change the characters of File_Name, but not its
length.

>type File_Name_Type is new String (1..12);
>
>then use:-
>
>procedure ...
>
>   File_Name : File_Name_Type;
>
>begin
>   :
>   File_Name := Text_IO.Name (File);
>   :
>end...
>
>or something similar. But unfortunately this is obviously not
>possible.

Did anyone suggest this:

    type String_Ptr is access String;

    procedure ...

       File_Name : String_Ptr;

    begin
       :
       File_Name := new String'(Text_IO.Name (File));
       :
    end...

?  Then you can change the length of the string by throwing away the old
one, and creating a new one on the heap.  In Ada 83, you have to worry
about storage management.  In Ada 95, you can encapsulate the storage
management using a controlled type -- and that's essentially what the
Strings.Unbounded package does.

- Bob




  parent reply	other threads:[~1997-04-05  0:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-04  0:00 [Q] Returning Strings From A Function John McCabe
1997-04-04  0:00 ` Joakim Olsson
1997-04-05  0:00 ` johnherro
1997-04-05  0:00   ` Mark & Zurima McKinney
1997-04-07  0:00     ` johnherro
1997-04-07  0:00       ` Robert Dewar
1997-04-07  0:00     ` Jon S Anthony
1997-04-07  0:00       ` johnherro
1997-04-08  0:00     ` Jeff Carter
1997-04-09  0:00     ` Looking for an Ada SCIENTIFIC UNITS checking package Ron House
1997-04-05  0:00   ` [Q] Returning Strings From A Function Robert Dewar
1997-04-06  0:00     ` John McCabe
1997-04-06  0:00       ` Robert Dewar
1997-04-05  0:00 ` John McCabe
1997-04-05  0:00   ` Robert Dewar
1997-04-06  0:00     ` John McCabe
1997-04-06  0:00       ` Matthew Heaney
1997-04-06  0:00       ` Robert Dewar
1997-04-06  0:00         ` Nick Roberts
1997-04-07  0:00           ` Robert A Duff
1997-04-08  0:00             ` Nick Roberts
1997-04-07  0:00               ` Matthew Heaney
1997-04-05  0:00   ` Robert A Duff [this message]
1997-04-06  0:00 ` John McCabe
replies disabled

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