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

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!widget!jjh
  3. From: jjh@evb.com (John Halper)
  4. Subject: Re: ADA question
  5. Message-ID: <1992Aug27.004228.19551@evb.com>
  6. Organization: EVB Software Engineering, Inc.
  7. Date: Thu, 27 Aug 1992 00:42:28 GMT
  8. Lines: 56
  9.  
  10. Daljeet writes:
  11.  
  12. >I am beginning to learn Ada and am stuck at a point. The question is as
  13. >follows:
  14. >
  15. >I have a function in a package A which returns string. I am using
  16. >that function in another package B and try to give the value returned
  17. >by that function to a variable (which has been declared in package B).
  18. >The variable is of type string (1 .. max) initialised to empty string.
  19. >My program simple raises an exception. 
  20. >Could it be that the array size is different for the variable and the value
  21. >returned by the function. The function can return a string of different
  22. >sizes. Can somebody give help me out?
  23.  
  24.  
  25. I will assume that for whatever reason, you are stuck with package A and
  26. can not rewrite the function as a procedure as per the suggestion of many
  27. others.  The solution given by Andrew Dunstan:
  28.  
  29.  
  30.  
  31.    declare
  32.       string_res : constant string := my_string_function;
  33.    begin
  34.       process(string_res);
  35.    end;
  36.  
  37.  
  38.  
  39. would be my next choice.  This is a slick answer and one I would have never
  40. thought of on my own.  Thanks.
  41.  
  42. Given that I was not allowed to use either of the above, IMHO better solutions, 
  43. how about the following:
  44.  
  45.  
  46.    declare 
  47.       String_Res : string (1..My_String_Function'length) := My_String_Function ;
  48.    begin 
  49.       Process (String_Res) ;
  50.    end ;
  51.  
  52.  
  53. I don't like making the call twice, and would rather use one of first two 
  54. solutions, but ...
  55.  
  56.  
  57. John Halper 
  58. EVB Software Engineering, Inc.
  59. 1 800 877 1815
  60. jjh@evb.com
  61. It would be presumptuous of me to even assume the company would want my opinions
  62. -- 
  63.  
  64. John Halper
  65. halper@evb.com
  66.