The tag, the whole tag, nothing but the tag, s'help me 
Author Message
 The tag, the whole tag, nothing but the tag, s'help me

I wonder how a person can declare a constant of a type which is a
null tagged record.  

Package Tag_Const is

   type Some_Tagged is tagged null record ;

   type Some_Other is new Some_Tagged with null record ;

   T  : constant Some_Tagged ;
   S  : constant Some_Other ;

   end ;

When I try to compile this specification, Gnat 2.07 complains (reasonably)

gcc -g -c tag_const.ads -o tag_const.o
tag_const.ads:7:04: missing full declaration for deferred constant
tag_const.ads:8:04: missing full declaration for deferred constant

Compilation exited abnormally with code 1 at Thu Sep 21 14:40:33
----

The objects T and S are constants, but neither has any initialization
expression.  Each does appear to be a "deferred constant," but I can't
think of any way to complete the declaration, so I haven't figured out
how such an object can exist.  Some advice, please?

--
John Woodruff                                             N I F   \ ^ /
Lawrence Livermore National Lab                         =====---- < 0 >
510 422 4661                                                      / v \



Mon, 09 Mar 1998 03:00:00 GMT  
 The tag, the whole tag, nothing but the tag, s'help me

Quote:

> I wonder how a person can declare a constant of a type which is a
> null tagged record.  

> Package Tag_Const is

>    type Some_Tagged is tagged null record ;

>    type Some_Other is new Some_Tagged with null record ;

>    T  : constant Some_Tagged ;
>    S  : constant Some_Other ;

>    end ;

> When I try to compile this specification, Gnat 2.07 complains (reasonably)

> gcc -g -c tag_const.ads -o tag_const.o
> tag_const.ads:7:04: missing full declaration for deferred constant
> tag_const.ads:8:04: missing full declaration for deferred constant

> Compilation exited abnormally with code 1 at Thu Sep 21 14:40:33
> ----

> The objects T and S are constants, but neither has any initialization
> expression.  Each does appear to be a "deferred constant," but I can't
> think of any way to complete the declaration, so I haven't figured out
> how such an object can exist.  Some advice, please?

John,

I am not sure exactly why you would want something like this save for
possibly using it for membership testing.  If that's the case, then
you may want to look into doing something like the following:

with Ada.Text_Io;

procedure Tag_Const is

   type Some_Tagged is tagged null record ;

   type Some_Other is new Some_Tagged with
     record
        I : Integer;
     end record;

   S1 : Some_Tagged;

   T : Some_Tagged'Class := Some_Other'(I => 1);
   S : Some_Tagged'Class := S1;

begin
   if T in Some_Tagged then
      Ada.Text_Io.Put_Line("T is a member of some_tagged.");
   end if;
   if S in Some_Tagged then
      Ada.Text_Io.Put_Line("S is a member of some_tagged.");
   end if;
end Tag_const;

This will fail the test of T and pass the test of S.

Hope this helps.
--



Tue, 10 Mar 1998 03:00:00 GMT  
 The tag, the whole tag, nothing but the tag, s'help me

Quote:

> I wonder how a person can declare a constant of a type which is a
> null tagged record.  

Ada 95 has null record aggregates:

    Foo: constant Null_Type := (null record);

See 4.3.1(3).

- Bob



Tue, 10 Mar 1998 03:00:00 GMT  
 The tag, the whole tag, nothing but the tag, s'help me

  > I wonder how a person can declare a constant of a type which is a
  > null tagged record....

  In Ada 95 you can write:

      T  : constant Some_Tagged := null record;
      S  : constant Some_Other := null record;

  or if you prefer:

      S : constant Some_Other := (T with null record);

  In Ada 83 it is possible to initialize an object of a null record
type, but it is more of a contest question than anything useful.

--

                                        Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...



Fri, 13 Mar 1998 03:00:00 GMT  
 The tag, the whole tag, nothing but the tag, s'help me


:   > I wonder how a person can declare a constant of a type which is a
:   > null tagged record....

:   In Ada 95 you can write:

:       T  : constant Some_Tagged := null record;
:       S  : constant Some_Other := null record;

Not quite.  Both of the above should be "(null record)".

:   or if you prefer:

:       S : constant Some_Other := (T with null record);

:   In Ada 83 it is possible to initialize an object of a null record
: type, but it is more of a contest question than anything useful.

: --

:                                       Robert I. Eachus


Intermetrics, Inc.



Sun, 15 Mar 1998 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. TAG AND DELETE (SUPER TAGGING)

2. tags and tag checking...

3. BLT tree tags: destroying associated treeview causes subsequent tag operations to fatally crash

4. tags and tag checking...

5. Text Tag Key Events Only Happen When Mouse is Over Tagged Area

6. TAGS, tags, tclTAGS?

7. Can the type Ada.Tags.Tag be used to instantiate a tagged type?

8. HELP - tag doesn't work

9. SUPER TAGGING HELP HELP HELP

10. Parsing HTML tags with 're'

11. Where's the Tagging Demo using styles (in C4)

12. Oberon-Tag '93 Summary

 

 
Powered by phpBB® Forum Software