home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / ada / 2456 < prev    next >
Encoding:
Text File  |  1992-08-27  |  1.6 KB  |  46 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!cis.ohio-state.edu!news.sei.cmu.edu!ae
  3. From: ae@sei.cmu.edu (Arthur Evans)
  4. Subject: Re: ADA question
  5. In-Reply-To: jjh@evb.com's message of Thu, 27 Aug 1992 00:42:28 GMT
  6. Message-ID: <1992Aug27.133957.8689@sei.cmu.edu>
  7. Sender: netnews@sei.cmu.edu (Netnews)
  8. Organization: Software Engineering Institute
  9. References: <1992Aug27.004228.19551@evb.com>
  10. Date: Thu, 27 Aug 1992 13:39:57 GMT
  11. Lines: 33
  12.  
  13. Several folks have responded to the request about how to deal with a
  14. function that returns a string.  In general such functions are hard to
  15. deal with, and better design is usually to adopt another approach.  Note,
  16. for example, how the Ada design specifies Text_IO.Getline in 14.3.6(12).
  17. (The first time I tried to use Text_IO.Name (ARM 14.2.1(20)) I had all
  18. the troubles the original poster had.)
  19.  
  20. If you are stuck with the string-returning function, you might declare a
  21. type that is an access to a string (that is, a pointer to a string) and
  22. store the string into a variable of that type.  It might look something
  23. like this, assuming that Get_It is the string-returning function:
  24.  
  25.     declare
  26.     type AString is access string;    -- pointer to a string
  27.     String_Val: AString;        -- variable to hold pointer
  28.     begin
  29.     ...
  30.     -- Get the string, and create a new place to store it.
  31.     String_Val := new string'(Get_It(...));
  32.     ... String_Val.all ...        -- reference to the string
  33.     ...
  34.  
  35.     end;
  36.  
  37. Good luck!
  38.  
  39. Art Evans
  40. ----------------------------------------------
  41. Arthur Evans, Jr, PhD           Ada Consultant
  42. 461 Fairview Road
  43. Pittsburgh PA  15238-1933
  44. 412-963-0839
  45. ae@sei.cmu.edu
  46.