Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: Ada.Contain...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 8 Topic 5697 of 5966
Post > Topic >>

Re: Ada.Containers.Vectors Update_Element issue

by Adam Beneschan <adam@[EMAIL PROTECTED] > May 14, 2008 at 08:17 AM

On May 14, 8:01 am, S=E9bastien <seb.mor...@[EMAIL PROTECTED]
> wrote:
>   > procedure Update_All (c : in out context) is
>
> >     procedure Do_The_Update (Element : in out Element_Type) is
> >     begin
> >         My_Update (c, Element);
> >     end Do_Update;
> > begin
> >     my_list.Update_Element (1, Do_The_Update'Access);
> > end Update_All;
>
> > I haven't tried this.  However, it should work because the Process
> > parameter to Update_Element is declared as an anonymous access-
> > procedure type, rather than as a named access-procedure type, and this
> > means you can pass a nested procedure access to it without any
> > accessibility-level issues.  (This sort of usage is exactly why
> > anonymous access-subprograms types were added to Ada 2005.)
>
> Ok I didn't think about nested proc having access to argument. When you
> mean anonymous access, you are meaning "Do_The_Update'Access"? There was
> no procedure access in previous ada version?

What I mean is that the procedure is declared with an anonymous access
subprogram parameter.  Here's the declaration of Update_Element in the
Vectors package:

   procedure Update_Element
     (Container : in out Vector;
      Index     : in     Index_Type;
      Process   : not null access procedure
                      (Element : in out Element_Type));

The declaration of Process is "not null access procedure".  This is an
*anonymous* access because the access type isn't given a name.  In Ada
95, you would have to make this a named access type:

   type Process_Type is access procedure (Element : in out
Element_Type);
        -- "not null" didn't exist in Ada 95
   procedure Update_Element
     (Container : in out Vector;
      Index     : in     Index_Type;
      Process   : in     Process_Type);

You can still do this in Ada 2005, but if you do, you would only be
allowed to pass Proc'Access as a parameter if Proc was a *global*
procedure (not nested inside any other procedure).  The reason is that
Update_Element could save Process in some global variable.  Sometimes
that's what you want---you want to be able to save a procedure access
and use it later.  But in the actual declaration, the Process
parameter is of an anonymous access type, which means that you can
pass an 'Access of any procedure, no matter how nested it is, but
Update_Element can't save the procedure access in a variable
anywhere.  Hope that explains things.

> Anyway it's working fine.

Great!

                                -- Adam
 




 8 Posts in Topic:
Ada.Containers.Vectors Update_Element issue
=?ISO-8859-1?Q?S=E9bastie  2008-05-13 17:26:40 
Re: Ada.Containers.Vectors Update_Element issue
Adam Beneschan <adam@[  2008-05-13 10:55:21 
Re: Ada.Containers.Vectors Update_Element issue
=?ISO-8859-1?Q?S=E9bastie  2008-05-14 15:01:00 
Re: Ada.Containers.Vectors Update_Element issue
Adam Beneschan <adam@[  2008-05-14 08:17:36 
Re: Ada.Containers.Vectors Update_Element issue
=?ISO-8859-1?Q?S=E9bastie  2008-05-14 18:21:30 
Re: Ada.Containers.Vectors Update_Element issue
Matthew Heaney <mheane  2008-05-14 14:25:21 
Re: Ada.Containers.Vectors Update_Element issue
Adam Beneschan <adam@[  2008-05-14 14:33:50 
Re: Ada.Containers.Vectors Update_Element issue
Ludovic Brenta <ludovi  2008-05-17 10:13:54 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 0:36:45 CST 2008.