Version 1.2 of ai05s/ai05-0259-1.txt

Unformatted version of ai05s/ai05-0259-1.txt version 1.2
Other versions for file ai05s/ai05-0259-1.txt

!standard 3.10(11)          11-06-19 AI05-0259-1/01
!class binding interpretation 11-06-19
!status work item 11-06-16
!status received 11-05-31
!priority Low
!difficulty Easy
!qualifier Omission
!subject Default convention of anonymous access-subprogram parameters
** TBD.
What is the convention of anonymous access-to-subprogram types in a subprogram that has another convention (like C)?
** TBD
Editor's one minute take:
Requiring the convention to be Ada would seem to cause problems for Import/Export. C is unlikely to be happy with an Ada closure.
OTOH, implementing the semantics of the access (for Convention/Export) would be a problem. How could one get a closure from C??
Thus the answer is not obvious here -- probably we need a combination of conventions and "recommended level of support".
** TBD.
** TBD.

!topic Default convention of anonymous access-subprogram parameters
!reference 3.10(11)
!from Adam Beneschan 11-05-31

3.10(11) says:

    An access_to_subprogram_definition defines an access-to-subprogram
    type and its first subtype; the parameter_profile or
    parameter_and_result_profile defines the designated profile of the
    access type.  There is a calling convention associated with the
    designated profile; only subprograms with this calling convention
    can be designated by values of the access type.  By default, the
    calling convention is "protected" if the reserved word protected
    appears, and "Ada" otherwise.  See Annex B for how to override
    this default.

Annex B doesn't explicitly say anything about how to override the convention of
a default *profile*.  I would assume, however, that for a named
access-to-subprogram type, specifying a Convention on the type is intended to
specify the convention of the designated profile; that is, in this example,

    type Callback_Type is access procedure (Arg : Data_Acc);
    pragma Convention (C, Callback_Type);

the convention of the designated profile is C, and that P'Access can be used for
a Callback_Type only if P has convention C.  I don't really mind the missing
wording too much here.

What about anonymous access-subprogram parameters?

    procedure Some_C_Operation
        (Callback : access procedure (Arg : Data_Acc));
    pragma Import (C, Some_C_Operation, "xxxxx");

The designated profile of the anonymous access type of Callback is Ada by
default, and I don't see anything that says that it gets the C convention even
though Some_C_Operation will have convention C.  Is this what is intended?


    type Access_To_C_Operation is access procedure
        (Callback : access procedure (Arg : Data_Acc));
    pragma Convention (C, Access_To_C_Operation);

The desginated profile of Access_To_C_Operation will have convention C, but what
about the designated profile of the anonymous access type of Callback?

(Of course, you could use named access types to get a profile with a C

    type Callback_Type is access procedure (Arg : Data_Acc);
    pragma Convention (C, Callback_Type);
    procedure Some_C_Operation (Callback : Callback_Type);
    pragma Import (C, Some_C_Operation, "xxxxx");

But then you couldn't pass it the 'access of a nested procedure:

    procedure Do_This is

        Z : Integer;

        procedure Do_That (Arg : Data_Acc);
        pragma Convention (C, Do_That);

        procedure Do_That (Arg : Data_Acc) is
             ... code that only accesses global variables
        end Do_That;

        Some_C_Operation (Do_That'access);  -- NOT LEGAL
    end Do_This;

I'm assuming things wouldn't work on all implementations if Do_That referenced
Z.  But if it didn't reference any "stack variables", it could be an annoyance
to require that Do_That be moved just so that 'access could be used.  Of course,
you could use 'Unrestricted_Access in some implementations but that would be
cheating.  :)

Anyway, this isn't urgent and certainly doesn't need to be addressed in Ada


Questions? Ask the ACAA Technical Agent