comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: Recursive tagged types
Date: 1997/11/10
Date: 1997-11-10T00:00:00+00:00	[thread overview]
Message-ID: <34675FB1.7C8@gsfc.nasa.gov> (raw)
In-Reply-To: 878950835.1236@dejanews.com


Adam Beneschan wrote:
> 
> GNAT outputs TRUE when I run this program.  Is this correct according
> to the Ada rules?

ObjectAda 7.1 on Windows 95 also reports TRUE.

It seems to me that declaring a type in a subprogram should not declare
a distinct type each time the subprogram is invoked. Consider the name
of the type; Test1.Recursive_Procedure.Type1. This does not change with
each invocation.

On the other hand, the RM seems pretty clear that they should be
distinct:

RM 3.2.1(11)

The elaboration of a full_type_declaration consists of the elaboration
of the full type definition. Each elaboration of a full type definition
creates a distinct type and its first subtype. 

RM 6.3 (7):

The execution of a subprogram_body is invoked by a subprogram call. For
this execution the declarative_part is elaborated, and the
handled_sequence_of_statements is then executed. 


> 
>                                 -- thanks, Adam
> 
> with Ada.Tags;
> with Text_IO;
> 
> procedure Test1 is
> 
>     Tag1 : Ada.Tags.Tag;
>     Tag2 : Ada.Tags.Tag;
> 
>     procedure Recursive_Procedure (N : in Integer) is
> 
>         type Type1 is tagged null record;
> 
>         type Type2 is new Type1 with record
>             Some_Data : Integer;
>         end record;
> 
>     begin
>         if N = 1 then
>             Tag1 := Type2'Tag;
>             Recursive_Procedure (2);
>         else
>             Tag2 := Type2'Tag;
>         end if;
>     end Recursive_Procedure;
> 
> begin
>     Recursive_Procedure (1);
>     Text_IO.Put_Line (Boolean'image (Ada.Tags."=" (Tag1, Tag2)));
> end Test1;
> 
> -------------------==== Posted via Deja News ====-----------------------
>       http://www.dejanews.com/     Search, Read, Post to Usenet

-- 
- Stephe




  reply	other threads:[~1997-11-10  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-11-07  0:00 Recursive tagged types Adam Beneschan
1997-11-10  0:00 ` Stephen Leake [this message]
1997-11-10  0:00   ` Tucker Taft
replies disabled

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