comp.lang.ada
 help / color / mirror / Atom feed
From: Tucker Taft <stt@averstar.com>
Subject: Re: Is this code legal
Date: 1999/06/14
Date: 1999-06-14T00:00:00+00:00	[thread overview]
Message-ID: <3765248A.9223B27B@averstar.com> (raw)
In-Reply-To: 929221299.108.55@news.remarQ.com

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);
> 
> <unrelated procedure sniped>
> 
> Procedure Update_Buffer is
> 
>    <unrelated declares sniped>
>     True_Buffer          : Unbounded_String renames Command_Buffer;
> 
>     <unrelated Declares sniped>
> 
>     Command_Buffer : Unbounded_string  := True_Buffer;
> 
>     <rest of procedure snipped>
> 
> 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




      parent reply	other threads:[~1999-06-14  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-12  0:00 Is this code legal Chad R. Meiners
1999-06-12  0:00 ` Matthew Heaney
1999-06-14  0:00 ` Tucker Taft [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox