home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada
- 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
- From: ucaa2385@ruscvx.rus.uni-stuttgart.de (Peter Hermann)
- Subject: Re: ADA question
- Message-ID: <1992Aug27.102951.8681@news.uni-stuttgart.de>
- Sender: news@news.uni-stuttgart.de (USENET News System)
- Organization: User ruscvx Comp.Center (RUS) University of Stuttgart, Germany
- References: <1992Aug27.004228.19551@evb.com>
- Date: Thu, 27 Aug 1992 10:29:51 GMT
- Lines: 38
-
- In article <1992Aug27.004228.19551@evb.com> jjh@evb.com (John Halper) writes:
- >Daljeet writes:
- >>I have a function in a package A which returns string. I am using
- >>that function in another package B and try to give the value returned
- >>by that function to a variable (which has been declared in package B).
- >>The variable is of type string (1 .. max) initialised to empty string.
- >
- >I don't like making the call twice, and would rather use one of first two
- >solutions, but ...
-
- It is advisable to call any function only once
- for the same purpose, because a function result
- 1. may change from call to call
- 2. may be expensive
-
- If and only if you have enough space or your strings
- to be processed are small enough, respectively,
- then you may code the following:
-
- DECLARE
- String_Const : CONSTANT String := My_String_Function;
- String_Var : String (String_Const'RANGE) := String_Const ;
- BEGIN
- Process (String_Var) ; -- parameter's mode: IN OUT
- END ;
-
- An advanced compiler may possibly sweat out the extra space
- for the constant. Perhaps all compilers of the next generation
- are apt enough?
-
- After all, I hope that Ada9x relaxes the situation anyway,
- in that a declaration like
- String_Var : String := My_String_Function;
- will become valid. This would create a constrained array
- by inspection of the initialization value.
-
- regards,
- Peter Hermann
-