home *** CD-ROM | disk | FTP | other *** search
- 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
- From: R_Tim_Coslet@cup.portal.com
- Newsgroups: comp.lang.ada
- Subject: Re: ADA question
- Message-ID: <64955@cup.portal.com>
- Date: Sun, 30 Aug 92 12:46:03 PDT
- Organization: The Portal System (TM)
- References: <1992Aug27.004228.19551@evb.com>
- <1992Aug27.102951.8681@news.uni-stuttgart.de>
- <8363@sirius.ucs.adelaide.edu.au>
- Lines: 32
-
- In article: <8363@sirius.ucs.adelaide.edu.au>
- andrewd@cs.adelaide.edu.au (Andrew Dunstan) writes...
- >This is based on my original suggestion, but copies the string into a
- >variable, which has to be done since "process" is now specified to
- >take an in out parameter. Unfortunately, this involves the cost of copying
- >the string, and if the code is called many times this cost can be substantial.
- >Remember that we really wanted a string variable in the first place, and
- >only used a constant because it meant we could decalre it without explicit
- >constraints. 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.
-
- OUCH! Don't ever do this! It is expressly forbidden in the Ada LRM to use
- the "for ... use at" clause for the purpose of overlaying data structures
- on top of each other and the results are totally undefined (especially if
- you are trying to overlay constants and variables... the constant might
- have been placed in ROM by the compiler and linker in certain environments)!
-
- R. Tim Coslet
-
- Usenet: R_Tim_Coslet@cup.portal.com
- California could REALLY use 40 days and 40 nights of rain right now!
-