comp.lang.ada
 help / color / mirror / Atom feed
From: "markww" <markww@gmail.com>
Subject: Re: how to import a package
Date: 10 Dec 2006 22:50:04 -0800
Date: 2006-12-10T22:50:04-08:00	[thread overview]
Message-ID: <1165819804.449958.305980@73g2000cwn.googlegroups.com> (raw)
In-Reply-To: <1165817760.736164.218530@73g2000cwn.googlegroups.com>

Ok I removed the 'access' keyword for the Next_Rec/Prev_Rec definitions
and that seems to have cleared that issue up.

I hope this is the last problem I run into , the rest of the app is
compiling ok. I used to have a procedure that would add a person_rec to
my linked list. I'm trying to update it so it takes a generic type and
gets added to the linked list instead. So I made a test function like:

     procedure Add_Record(GenericData : gNode.T) is
     Temp : gNode.Node_Ptr;
     begin
         Temp := new gNode.Node;
         Temp.Data := GenericData;
     end Add_Record;

now the compiler is saying that my generic type T is not visible to the
rest of the application. It's in the imported package though and all
the rest of the parts are visible. How do I make it visible?

Also, is this procedure definition correct? In C++ it's easy to do this
after defining a type it would be just:

    bool Add_Record (T t);
    template<typename T>
    bool CLinkedList<T>::Add_Record(T t)
    {
        // ...
    }

I'm guessing it must be similar.

Thanks,
Mark




markww wrote:
> Ok I still don't understand why this assignment is illegal though -
> here's a test I have:
>
>     generic
>         type T is private;
>     package GenericNode is
>         type Node;
>         type Node_Ptr is access Node;
>         type Node is record
>             Data     : T;           -- the generic data we want to
> store in a node.
>             Prev_Rec : access Node_Ptr; -- points to the next record or
> null if none exists.
>             Next_Rec : access Node_Ptr; -- points to the previous
> record or null if none exists.
>         end record;
>     end GenericNode;
>
> now later...
>
>     package gNode is new GenericNode(T => PERSON_REC);
>     use gNode;
>
>     function Test(whatever : INTEGER) return INTEGER is
>     Temp : gNode.Node_Ptr;
>     begin
>         Temp := Temp.Next_Rec; -- no!!!!!!!!!!!!!!!!
>         return 0;
>     end Test;
>
> Why is the Temp assignment not possible? The compiler says: expected
> type Node_Ptr defined in genericnode.ads. But I have defined it as type
> Node_Ptr.
>
> Thanks,
> Mark
>
>
>
> Jean-Pierre Rosen wrote:
> > Stuart a écrit :
> > >    package body P is
> > >       type T is array(0..5) of integer;
> > >       A, B : array(0..5) of integer;
> > >       C, D : T;
> > >    begin
> > >       A := B;
> > >       -- Not allowed because types don't match!
> > >       C := D;
> > >       -- Types match!
> > >    end P;
> > >
> > > [...]
> > > However, both C and D are of the same named type - even though the type T
> > > has an anonymous type as an index range.  I think it is better to avoid
> > > anonymous types - so the declaration of T might be better written as:
> > >       type T_index is range 0..5;
> > >       type T is array(T_index) of integer;
> > >
> > Just nit-picking, the index type of T is not anonymous, it is
> > Standard.Integer by default, therefore the aboved declaration is not
> > equivalent.
> >
> > Agreed, it is best to avoid hidden use of Standard.Integer. If you need
> > Integer as the index type, better use:
> > type T is array (Integer range 0..5) of Integer;
> >
> > Note that this remark is also applicable to loops. Rather than:
> > for I in 1..10 loop
> >
> > write:
> > for I in Integer range 1..10 loop
> >
> > (small plug: there is a rule in AdaControl to check the above)
> > --
> > ---------------------------------------------------------
> >             J-P. Rosen (rosen@adalog.fr)
> > Visit Adalog's web site at http://www.adalog.fr




  reply	other threads:[~2006-12-11  6:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-06  2:14 how to import a package markww
2006-12-06  3:06 ` Adam Beneschan
2006-12-06  3:34   ` markww
2006-12-06  9:18     ` Simon Wright
2006-12-06 19:47 ` Jeffrey R. Carter
2006-12-06 23:56   ` markww
2006-12-07  1:18     ` Björn Persson
2006-12-07  1:26     ` Brian May
2006-12-07  4:14       ` markww
2006-12-07  4:40         ` Brian May
2006-12-07  9:32           ` Stuart
2006-12-07 11:21             ` Jean-Pierre Rosen
2006-12-11  6:16               ` markww
2006-12-11  6:50                 ` markww [this message]
2006-12-11  9:40                   ` Georg Bauhaus
2006-12-11 14:19                     ` markww
2006-12-11 15:03                       ` Dmitry A. Kazakov
2006-12-11 16:22                       ` Adam Beneschan
2006-12-11 20:28                       ` Jeffrey R. Carter
2006-12-12  3:19                         ` markww
2006-12-12  3:31                           ` Jeffrey R. Carter
2006-12-12  9:03                           ` Stuart
2006-12-12 10:56                           ` Georg Bauhaus
2006-12-11  7:00                 ` Simon Wright
2006-12-07  4:06     ` Jeffrey R. Carter
replies disabled

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