home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada
- Path: sparky!uunet!telesoft!kst
- From: kst@telesoft.com (Keith Thompson @pulsar)
- Subject: Re: ADA question
- Message-ID: <1992Aug30.081648.4039@telesoft.com>
- Organization: TeleSoft, San Diego, CA, USA
- References: <1992Aug27.004228.19551@evb.com> <1992Aug27.102951.8681@news.uni-stuttgart.de> <8363@sirius.ucs.adelaide.edu.au>
- Date: Sun, 30 Aug 1992 08:16:48 GMT
- Lines: 42
-
- In article <8363@sirius.ucs.adelaide.edu.au> andrewd@cs.adelaide.edu.au (Andrew Dunstan) writes:
- > [...] To avoid the cost of copying, you could try this, although it
- > won't necessarily work on all compilers:
- >
- > DECLARE
- > String_Const : CONSTANT String := My_String_Function;
- > String_Var : String (String_Const'RANGE) ;
- > for string_var use at string_const'address ;
- > BEGIN
- > Process (String_Var) ; -- parameter's mode: IN OUT
- > END ;
- >
- > Now there is no copying, and no extra storage allocation. It's a bit gross,
- > but it should work.
-
- It may work in some implementations, but your program may break in odd
- ways when you port it to another compiler, recompile with a new
- optimization flag, or try compiling or executing it during the wrong
- phase of the moon. What you're trying to do here is create an overlay
- between String_Const and String_Var. LRM 13.5:8 says
-
- Address clauses should not be used to achieve overlays of
- objects or overlays of program units. Nor should a given
- interrupt be linked to more than one entry. Any program using
- address clauses to achieve such effects is erroneous.
-
- "Erroneous" means that it violates the rules of the language, but an
- implementation is not required to detect the violation either at
- compilation time or at run time (though I know of at least one
- implementation that issues a warning in this case). The effect of
- erroneous execution is unpredictable (LRM 1.6:7).
-
- IMHO, it's not worth it to avoid the minor cost of a string copy.
- The hours wasted by your successor ten years from now trying to figure out
- why the program stopped working are more important than the microseconds
- you'll save in execution time. Besides, a sufficiently smart optimizing
- compiler might eliminate the copy for you anyway (though I don't know
- whether any current compilers do so).
- --
- Keith Thompson (The_Other_Keith) kst@telesoft.com
- TeleSoft, 5959 Cornerstone Court West, San Diego, CA, 92121-9891
- "Listen to me, people! We must stick them with quills -- it's the only way!"
-