comp.lang.ada
 help / color / mirror / Atom feed
From: je@bton.ac.uk (John English)
Subject: Re: Procedure Access Values
Date: 1998/02/13
Date: 1998-02-13T00:00:00+00:00	[thread overview]
Message-ID: <6c2cds$2ej@saturn.brighton.ac.uk> (raw)
In-Reply-To: 34E2B8C3.4D61@dera.gov.uk


Anton Gibbs (agibbs@dera.gov.uk) wrote:
: This all works fine. The problem we have run into occurs when we
: convert package P into a generic. ie:-

: generic package P is
:    procedure Start;
: end P;

: with Notifiers; 
: package body P is
:    procedure Event_Handler is ...;
:    
:    procedure Start is
:    begin 
:       Notifiers.Notify_Me_When_Event_Occurs( Event_Handler'Access );--*
:    end Start;
:  
: end P;

This will be a problem if you instantiate your generic inside a procedure.
The elaboration of the package body happens at the point of instantiation,
i.e. one lexical level deeper than the level (library level) at which
Notifiers.Event_Handler is declared. The solution is to instantiate
the generic in a library level package, i.e.

  with P;
  package Q is
    package R is new P;  -- the access value in R is at the same level as P
  end Q;

  with Q;
  procedure Main is
    -- use Q.R here
  end Main;

rather than:

  with P;
  procedure Main is
    package R is new P;  -- R contains an access created at the wrong
    ...			 -- lexical level
  end Main;

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------




  reply	other threads:[~1998-02-13  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-02-12  0:00 Procedure Access Values Anton Gibbs
1998-02-13  0:00 ` John English [this message]
  -- strict thread matches above, loose matches on Subject: below --
1998-02-03  0:00 Anton Gibbs
replies disabled

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