comp.lang.ada
 help / color / mirror / Atom feed
  • * Re: Self-referential types
           [not found] <7ttb4a$8mq$1@nnrp1.deja.com>
           [not found] ` <3802597B.9205AEE8@averstar.com>
    @ 1999-10-12  0:00 ` Robert A Duff
      1999-10-12  0:00 ` Vladimir Olensky
      2 siblings, 0 replies; 62+ messages in thread
    From: Robert A Duff @ 1999-10-12  0:00 UTC (permalink / raw)
    
    
    Ted Dennison <dennison@telepath.com> writes:
    
    > I'm trying to create my first self referential type. But there's
    > obviously something about this technique I'm missing, because all
    > attempts produce compiler errors in multiple compilers.
    > 
    > Below is a code sample that is taken directly from Cohen's AAASL,
    > section 11.8.3:
    > 
    > procedure Test is
    > 
    >    type Cell_Type;
    > 
    >    type List_Type is access all Cell_Type;
    > 
    >    type Cell_Type is
    >      limited record
    >         Contents_Part      : String (1..20);
    >         Next_Cell_Part     : List_Type := Cell_Type'Access;
    >         Previous_Cell_Part : List_Type := Cell_Type'Access;
    >      end record;
    > begin
    >    null;
    > end Test;
    > 
    > Compiling this with Gnat gives me:
    > Test.adb:10:43: non-local pointer cannot point to local object
    > Test.adb:11:43: non-local pointer cannot point to local object
    > 
    > I don't see an accesability level problem here, ...
    
        X: List_Type;
    
        procedure Nested is
            Local: Cell_Type;
        begin
            X := Local.Next_Cell_Part;
        end Nested;
    
        Nested;
        
        ... X.all ... -- Here, X is a dangling pointer.
    
    That's the accessibility level problem.  You need to use
    'Unchecked_Access, and you need to be careful not to do the above.
    The language design tries to prevent dangling pointers
    unless you do something "unchecked".
    
    >...and it looks like it
    > thinks Cell_Type is an object, not a type.
    
    It *is* an object -- the "current instance" of the type (sort of like
    "self" or "this" in some other languages).
    
    - Bob
    -- 
    Change robert to bob to get my real email address.  Sorry.
    
    
    
    
    ^ permalink raw reply	[flat|nested] 62+ messages in thread
  • * Re: Self-referential types
           [not found] <7ttb4a$8mq$1@nnrp1.deja.com>
           [not found] ` <3802597B.9205AEE8@averstar.com>
      1999-10-12  0:00 ` Robert A Duff
    @ 1999-10-12  0:00 ` Vladimir Olensky
      1999-10-12  0:00   ` Matthew Heaney
      2 siblings, 1 reply; 62+ messages in thread
    From: Vladimir Olensky @ 1999-10-12  0:00 UTC (permalink / raw)
    
    
    
    Ted Dennison wrote in message <7ttb4a$8mq$1@nnrp1.deja.com>...
    >I'm trying to create my first self referential type. But there's
    >obviously something about this technique I'm missing, because all
    >attempts produce compiler errors in multiple compilers.
    >
    >Below is a code sample that is taken directly from Cohen's AAASL,
    >section 11.8.3:
    >
    >procedure Test is
    >
    >   type Cell_Type;
    >
    >   type List_Type is access all Cell_Type;
    >
    >   type Cell_Type is
    >     limited record
    >        Contents_Part      : String (1..20);
    >        Next_Cell_Part     : List_Type := Cell_Type'Access;
    >        Previous_Cell_Part : List_Type := Cell_Type'Access;
    >     end record;
    >begin
    >   null;
    >end Test;
    
    
    
    
    It seems that this example  was not tested.
    
    How it is  possible to initialize access variable
    by the initial value that is access attribute to type ?
    Access attributes can not be applied to type.
    It may only be  applied to some object but not to its description.
    
    Also compiles are probably giving  misleading error messages.
    
    If you change your example to:
    -------------------------------------
    Procedure Test is
        type Cell_Type;
        type List_Type is access all Cell_Type;
    
        type Cell_Type is    limited record
            Contents_Part : String (1..20);
            Next_Cell_Part : List_Type := null;
            Previous_Cell_Part : List_Type := null;
        end record;
    
     Wrong_Initialization : List_Type := Cell_Type'Access;
    
    begin
        null;
    end Test;
    ------------------------------------------
    than you will have right error message regarding
    Wrong_Initialization  varible:
    
    >>>test.adb:14:37: "Access" attribute cannot be applied to type
    gnatmake: "test.adb" compilation error
    
    Regards,
    Vladimir Olensky
    
    
    
    
    
    
    
    ^ permalink raw reply	[flat|nested] 62+ messages in thread

  • end of thread, other threads:[~1999-10-28  0:00 UTC | newest]
    
    Thread overview: 62+ messages (download: mbox.gz / follow: Atom feed)
    -- links below jump to the message on this page --
         [not found] <7ttb4a$8mq$1@nnrp1.deja.com>
         [not found] ` <3802597B.9205AEE8@averstar.com>
    1999-10-12  0:00   ` Self-referential types Ted Dennison
    1999-10-12  0:00     ` Matthew Heaney
    1999-10-13  0:00       ` Ted Dennison
    1999-10-12  0:00 ` Robert A Duff
    1999-10-12  0:00 ` Vladimir Olensky
    1999-10-12  0:00   ` Matthew Heaney
    1999-10-12  0:00     ` Ted Dennison
    1999-10-12  0:00       ` Matthew Heaney
    1999-10-12  0:00     ` Robert I. Eachus
    1999-10-12  0:00       ` Matthew Heaney
    1999-10-13  0:00         ` Vladimir Olensky
    1999-10-13  0:00           ` Vladimir Olensky
    1999-10-18  0:00           ` Robert Dewar
    1999-10-18  0:00             ` Vladimir Olensky
    1999-10-18  0:00             ` Laurent Guerby
    1999-10-13  0:00         ` Ted Dennison
    1999-10-13  0:00           ` Matthew Heaney
    1999-10-13  0:00         ` Robert I. Eachus
    1999-10-13  0:00           ` Brian Rogoff
    1999-10-15  0:00             ` Robert I. Eachus
    1999-10-15  0:00               ` Marin David Condic
    1999-10-15  0:00                 ` Robert I. Eachus
    1999-10-18  0:00                   ` Robert Dewar
    1999-10-19  0:00                     ` Robert I. Eachus
    1999-10-18  0:00               ` Robert Dewar
    1999-10-18  0:00                 ` Brian Rogoff
    1999-10-18  0:00                 ` Ed Falis
    1999-10-19  0:00                   ` Robert Dewar
         [not found]               ` <7u86su$o5v$1@nntp8.atl.mindspring.net>
    1999-10-18  0:00                 ` Robert I. Eachus
    1999-10-22  0:00                   ` Richard D Riehle
    1999-10-22  0:00                     ` Robert I. Eachus
         [not found]               ` <slrn80fl9f.68j.aidan@skinner.demon.co.uk>
    1999-10-19  0:00                 ` Wes Groleau
    1999-10-21  0:00                   ` Robert Dewar
    1999-10-21  0:00                     ` Jean-Pierre Rosen
    1999-10-21  0:00                       ` Robert Dewar
    1999-10-21  0:00                     ` Larry Kilgallen
    1999-10-21  0:00                     ` Comments (was: Self-referential types) Wes Groleau
    1999-10-21  0:00                       ` Ehud Lamm
    1999-10-22  0:00                         ` Ted Dennison
    1999-10-23  0:00                           ` Ehud Lamm
    1999-10-23  0:00                         ` Robert Dewar
    1999-10-23  0:00                           ` Ehud Lamm
    1999-10-23  0:00                             ` Comments Georg Bauhaus
    1999-10-24  0:00                               ` Comments Ehud Lamm
    1999-10-26  0:00                                 ` Comments Robert I. Eachus
    1999-10-28  0:00                                   ` Comments Jerry van Dijk
    1999-10-28  0:00                                     ` Comments Ted Dennison
    1999-10-25  0:00                             ` Comments (was: Self-referential types) Wes Groleau
    1999-10-23  0:00                       ` M.
         [not found]                       ` <Pine.A41.3.96-heb-2.07.991021191504.30582K-100000@pluto.mscc.huji. <381477c9.e1388ff3@ftw.rsc.raytheon.com>
    1999-10-25  0:00                         ` Larry Kilgallen
    1999-10-22  0:00                     ` Self-referential types Richard D Riehle
    1999-10-23  0:00                       ` Robert A Duff
    1999-10-23  0:00                         ` Richard D Riehle
    1999-10-24  0:00                       ` Michel DELARCHE
    1999-10-12  0:00     ` Richard D Riehle
    1999-10-12  0:00     ` news.oxy.com
    1999-10-12  0:00       ` Ted Dennison
    1999-10-12  0:00         ` Stanley R. Allen
    1999-10-13  0:00           ` Ted Dennison
    1999-10-13  0:00         ` Vladimir Olensky
    1999-10-14  0:00         ` Multiple Inheritance in Ada 95 [was Re: Self-referential types] Tucker Taft
    1999-10-12  0:00       ` Self-referential types Matthew Heaney
    

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