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

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