home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / ada / 2485 < prev    next >
Encoding:
Internet Message Format  |  1992-08-30  |  2.0 KB

  1. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!jvnc.net!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!sdd.hp.com!decwrl!nntp1.radiomail.net!portal!cup.portal.com!R_Tim_Coslet
  2. From: R_Tim_Coslet@cup.portal.com
  3. Newsgroups: comp.lang.ada
  4. Subject: Re: ADA question
  5. Message-ID: <64955@cup.portal.com>
  6. Date: Sun, 30 Aug 92 12:46:03 PDT
  7. Organization: The Portal System (TM)
  8. References: <1992Aug27.004228.19551@evb.com>
  9.   <1992Aug27.102951.8681@news.uni-stuttgart.de>
  10.   <8363@sirius.ucs.adelaide.edu.au>
  11. Lines: 32
  12.  
  13. In article: <8363@sirius.ucs.adelaide.edu.au>
  14.     andrewd@cs.adelaide.edu.au (Andrew Dunstan) writes...
  15. >This is based on my original suggestion, but copies the string into a
  16. >variable, which has to be done since "process" is now specified to
  17. >take an in out parameter. Unfortunately, this involves the cost of copying
  18. >the string, and if the code is called many times this cost can be substantial.
  19. >Remember that we really wanted a string variable in the first place, and
  20. >only used a constant because it meant we could decalre it without explicit
  21. >constraints. To avoid the cost of copying, you could try this, although it
  22. >won't necessarily work on all compilers:
  23. >
  24. > DECLARE
  25. >    String_Const : CONSTANT String := My_String_Function;
  26. >    String_Var : String (String_Const'RANGE) ;
  27. >    for string_var use at string_const'address ;
  28. > BEGIN
  29. >    Process (String_Var) ; -- parameter's mode: IN OUT
  30. > END ;
  31. >Now there is no copying, and no extra storage allocation. It's a bit gross,
  32. >but it should work.
  33.  
  34. OUCH! Don't ever do this! It is expressly forbidden in the Ada LRM to use
  35. the "for ... use at" clause for the purpose of overlaying data structures
  36. on top of each other and the results are totally undefined (especially if
  37. you are trying to overlay constants and variables... the constant might
  38. have been placed in ROM by the compiler and linker in certain environments)!
  39.  
  40.                                         R. Tim Coslet
  41.  
  42. Usenet: R_Tim_Coslet@cup.portal.com
  43. California could REALLY use 40 days and 40 nights of rain right now!
  44.