[comp.lang.ada] Pointers to code

arra@stellar.COM (Arra Avakian @stellar) (08/31/89)

Bill Wolfe, wtwolfe@hubcap.clemson.edu, writes in referencing to calling a
function given its address:

>    ...  The major restriction,
>    then, is not an inability to store a pointer to a function in a record
>    type; rather, it is the fact that there is not a mechanism which can
>    express the desire to invoke the function residing at that address;
>    the 9X proposed revision would therefore provide such a mechanism. 
>

It seems there is a syntax in Ada for calling a subprogram, given its address
at run time. However, it depends upon an interpretation of an address clause
for a subprogram that may not be what was intended in the ARM (13.5),
paragraph 5:

"b) Name of a subprogram, package, or task unit: the address that is required
 for the machine code associated with the body of the program unit."

I believe that was is intended is that the corresponding body, which is
expected to occur later, will be placed in some system dependent manner by
a linker/loader at the given (presumably static) address. However, another 
interpretation is that the body will NOT be supplied in Ada, but that the 
machine code for it will be found at the given (possibly non-static) address. 
So here it is (a different version for every signature is required, only 
one example given):

--
-- "call(p,i)" will call a procedure given by address "p" with argument "i"
--
with SYSTEM;

procedure CALL(PROC: SYSTEM.ADDRESS; ARG: INTEGER) is

    -- Define a dummy procedure at address "PROC"
    procedure DUMMY(I: INTEGER);
    for DUMMY use at PROC;

begin
    DUMMY(I => ARG);
end CALL;

=========================
    arra@stellar.com 
    Arra Avakian
    Stellar Computer Inc
    95 Wells Ave
    Newton, MA 02159
    (617) 964-1000 xt 288