comp.lang.ada
 help / color / mirror / Atom feed
* Is this code legal
@ 1999-06-12  0:00 Chad R. Meiners
  1999-06-12  0:00 ` Matthew Heaney
  1999-06-14  0:00 ` Tucker Taft
  0 siblings, 2 replies; 3+ messages in thread
From: Chad R. Meiners @ 1999-06-12  0:00 UTC (permalink / raw)


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.

-Chad R. Meiners







^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is this code legal
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Matthew Heaney @ 1999-06-12  0:00 UTC (permalink / raw)


On 12 Jun 1999 15:59, "Chad R. Meiners" <crmeiners@hotmail.com> wrote:

> 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.

In Ada95, functions return "constant objects" (as opposed to "values,"
which is what functions returned in Ada83), so renaming the result of a
function call should be legal.

Maybe you have an aliasing problem???  I'm not sure...

Matt







^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is this code legal
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Tucker Taft @ 1999-06-14  0:00 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1999-06-14  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox