From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1556a5535c129d37 X-Google-Attributes: gid103376,public From: Tucker Taft Subject: Re: Is this code legal Date: 1999/06/14 Message-ID: <3765248A.9223B27B@averstar.com>#1/1 X-Deja-AN: 489477965 Content-Transfer-Encoding: 7bit Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.burl.averstar.com References: <929221299.108.55@news.remarQ.com> Content-Type: text/plain; charset=us-ascii Organization: AverStar (formerly Intermetrics) Burlington, MA USA Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-06-14T00:00:00+00:00 List-Id: Chad R. Meiners wrote: > > Yesterday I tracked down a bug in one of my programs where an Unbounded > string was containing garbage and causing Index_errors. I traced the > problem to the following code. > > -- All of this code is inside a procedure of a protected object > > Function Command_Buffer return Unbounded_String is > > -- Command_Buffers is an array of Unbounded_strings > -- Current_Buffer is an index in this array which is the index of the > current_buffer > > begin > > return Command_Buffers(Current_Buffer); > > end Command_Buffer; > pragma Inline(Command_Buffer); > > > > Procedure Update_Buffer is > > > True_Buffer : Unbounded_String renames Command_Buffer; > > > > Command_Buffer : Unbounded_string := True_Buffer; > > > > I have fixed the code by changing the True_Buffer declaration to an > assignment as opposed to a renaming. > I was wondering such a renaming is legal in Ada 95 since True_Buffer is an > Unbounded_String and Command_Buffer is a function. > > Any help would be appricated. This looks like a compiler bug. What you are doing is entirely legal and non-erroneous, so it shouldn't produce "garbage" in the various unbounded strings. Generally the rename of a function return is identical to the assignment of the value, for non-limited types. For limited types, only the rename is permitted. > -Chad R. Meiners -- -Tucker Taft stt@averstar.com http://www.averstar.com/~stt/ Technical Director, Distributed IT Solutions (www.averstar.com/tools) AverStar (formerly Intermetrics, Inc.) Burlington, MA USA