comp.lang.ada
 help / color / mirror / Atom feed
From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!us
Subject: Re: Passing procedures as parameters to procedures.
Date: 5 May 93 16:30:56 GMT	[thread overview]
Message-ID: <C6KB7K.ECA@irvine.com> (raw)

In article <1993May4.221355.13487@evb.com> jgg@evb.com (John Goodsen) writes:

>   In article <1993May3.190746.1043@ee.ubc.ca> luisl@ee.ubc.ca 
>       (luis linares-rojas) writes:
>   >Subject: Procedures/functions as parameters to procedures/functions.
>   >Before commiting myself to any long term commitment with the Ada
>   >language, I've been revising its capabilities.  There is
>   >something that I have not found so far: how to pass a procedure
>   >(or a function) as a parameter to another procedure (or
>   >function).  Or, in the same spirit, how to create an array of
>   >procedures.  The question is: is there a way of doing this in
>   >Ada, and (if so) how?  I'd appreciate any help.
>
>   If you can't wait for Ada 9X and you need dynamic binding of 
>   the procedure to call, then you might also check out how it's
>   currently done in the Xt/Motif bindings which support call by
>   address of Ada procedures from C.  Basically, you 
>   pass the address of an Ada procedure to an external routine 
>   using the 'ADDRESS attribute and have that routine call the Ada routine 
>   that was passed to it.  Of course, this has the usual side effects 
>   of being compiler dependent, etc... but it works in Ada 83.

If you do this, be aware that you may not be able to do this for
nested procedures.  In our compiler, and probably in other Ada
compilers, nested procedures take "hidden" parameters, e.g.:

    procedure A (x : integer) is
       local_variable : integer;
       procedure B (y : integer) is
       begin
          ...
       end B;
    begin
       ...
    end A;

The code for B actually takes two parameters;  the extra parameter is
a frame pointer that allows B to access local variables defined in A
(such as local_variable).  So if you pass B'ADDRESS to a C or
assembly-language routine that tries to call B, you will not get the
desired results.

                               -- Adam
       

             reply	other threads:[~1993-05-05 16:30 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-05-05 16:30 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!us [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-05-10 22:56 Passing procedures as parameters to procedures Jack Dean
1993-05-06  9:39 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!darwi
1993-05-06  7:33 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!torn!
1993-05-05 21:35 cis.ohio-state.edu!news.sei.cmu.edu!ajpo.sei.cmu.edu!progers
1993-05-05 17:39 Robert Dewar
1993-05-05 17:35 Robert Dewar
1993-05-05 11:40 cis.ohio-state.edu!news.sei.cmu.edu!firth
1993-05-05  9:50 cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland.
1993-05-04 23:44 cis.ohio-state.edu!magnus.acs.ohio-state.edu!zaphod.mps.ohio-state.edu!ho
1993-05-04 22:13 John Goodsen
1993-05-04 19:39 cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!m
1993-05-04 16:41 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!ira.u
1993-05-04 16:25 Mark A Biggar
1993-05-04 15:43 Tucker Taft
1993-05-04 14:29 cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uwm.edu!spool.mu.edu!
1993-05-04 13:59 Tucker Taft
1993-05-04 13:45 cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland.
1993-05-04 13:45 cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uwm.edu!cs.utexas.edu
1993-05-04 10:25 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!us
1993-05-03 20:36 Mark A Biggar
1993-05-03 19:07 cis.ohio-state.edu!magnus.acs.ohio-state.edu!zaphod.mps.ohio-state.edu!ho
replies disabled

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