Search code examples
ada

Access type and procedures


I am writing with reference to my earlier post here:

Ada 2005 access type

In the first code diff.adb, there is the line:

procedure Solve is new Euler(Real, Vector, Ptr);

I don't understand how come the arguments of Euler area Real, Vector and Ptr because further down in the same code we have

Solve(Ident'Access, 1.0, 0.1, Answer);

with 4 arguments.

The original codes at the previous link are OK and are working.


Solution

  • The first line is an example of Generic Instantiation. It creates an instance of the generic procedure Euler, passing the three concrete types required. The actual types supplied in the instantiation—Real, Vector and Ptr— match the Formal Types specified in euler.ads: Float_Type, Vector and Function_Ptr, in that order. Note that either positional or named association is permitted.

    The second line is a Subprogram Call of the newly created procedure instance, which has four actual parameters: a Function_Ptr, two Real values and an output Vector. The new instance is named Solve, and it now has the same parameter profile as the procedure Euler.

    What's the difference between a subprogram parameter (starting with keyword with) and a subprogram declaration?

    In your example, Euler is not a formal subprogram declaration, which requires with; it is a generic subprogram specification, which does not. The examples may help illustrate the difference.