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

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!jvnc.net!yale.edu!ira.uka.de!news.belwue.de!news.uni-stuttgart.de!ruscvx.rus.uni-stuttgart.de!ucaa2385
  3. From: ucaa2385@ruscvx.rus.uni-stuttgart.de (Peter Hermann)
  4. Subject: Re: ADA question
  5. Message-ID: <1992Aug27.102951.8681@news.uni-stuttgart.de>
  6. Sender: news@news.uni-stuttgart.de (USENET News System)
  7. Organization: User ruscvx Comp.Center (RUS) University of Stuttgart, Germany
  8. References: <1992Aug27.004228.19551@evb.com>
  9. Date: Thu, 27 Aug 1992 10:29:51 GMT
  10. Lines: 38
  11.  
  12. In article <1992Aug27.004228.19551@evb.com> jjh@evb.com (John Halper) writes:
  13. >Daljeet writes:
  14. >>I have a function in a package A which returns string. I am using
  15. >>that function in another package B and try to give the value returned
  16. >>by that function to a variable (which has been declared in package B).
  17. >>The variable is of type string (1 .. max) initialised to empty string.
  18. >
  19. >I don't like making the call twice, and would rather use one of first two 
  20. >solutions, but ...
  21.  
  22. It is advisable to call any function only once
  23. for the same purpose, because a function result
  24.  1. may change from call to call
  25.  2. may be expensive
  26.  
  27. If and only if you have enough space or your strings
  28. to be processed are small enough, respectively,
  29. then you may code the following:
  30.  
  31. DECLARE
  32.    String_Const : CONSTANT String := My_String_Function;
  33.    String_Var : String (String_Const'RANGE) := String_Const ;
  34. BEGIN
  35.    Process (String_Var) ; -- parameter's mode: IN OUT
  36. END ;
  37.  
  38. An advanced compiler may possibly sweat out the extra space
  39. for the constant. Perhaps all compilers of the next generation
  40. are apt enough?
  41.  
  42. After all, I hope that Ada9x relaxes the situation anyway,
  43. in that a declaration like
  44.    String_Var : String := My_String_Function;
  45. will become valid. This would create a constrained array
  46. by inspection of the initialization value.
  47.  
  48. regards,
  49. Peter Hermann
  50.