Lady Ada

Ada '83 Language Reference Manual

Copyright 1980, 1982, 1983 owned by the United States Government. Direct reproduction and usage requests to the Ada Information Clearinghouse.

6.6. Parameter and Result Type Profile - Overloading of Subprograms


Two formal parts are said to have the same parameter type profile if and only if they have the same number of parameters, and at each parameter position corresponding parameters have the same base type. A subprogram or entry has the same parameter and result type profile as another subprogram or entry if and only if both have the same parameter type profile, and either both are functions with the same result base type, or neither of the two is a function.

The same subprogram identifier or operator symbol can be used in several subprogram specifications. The identifier or operator symbol is then said to be overloaded; the subprograms that have this identifier or operator symbol are also said to be overloaded and to overload each other. As explained in section 8.3, if two subprograms overload each other, one of them can hide the other only if both subprograms have the same parameter and result type profile (see section 8.3 for the other requirements that must be met for hiding).

A call to an overloaded subprogram is ambiguous (and therefore illegal) if the name of the subprogram, the number of parameter associations, the types and the order of the actual parameters, the names of the formal parameters (if named associations are used), and the result type (for functions) are not sufficient to determine exactly one (overloaded) subprogram specification.

Examples of overloaded subprograms:

    procedure PUT(X : INTEGER);
    procedure PUT(X : STRING); 

    procedure SET(TINT   : COLOR);
    procedure SET(SIGNAL : LIGHT); 

Examples of calls:

    PUT("no possible ambiguity here"); 

    SET(TINT   => RED);

    --  SET(RED) would be ambiguous since RED may
    --  denote a value either of type COLOR or of type LIGHT 


The notion of parameter and result type profile does not include parameter names, parameter modes, parameter subtypes, default expressions and their presence or absence.

Ambiguities may (but need not) arise when actual parameters of the call of an overloaded subprogram are themselves overloaded function calls, literals, or aggregates. Ambiguities may also (but need not) arise when several overloaded subprograms belonging to different packages are visible. These ambiguities can usually be resolved in several ways: qualified expressions can be used for some or all actual parameters, and for the result, if any; the name of the subprogram can be expressed more explicitly as an expanded name; finally, the subprogram can be renamed.

References: actual parameter, aggregate, base type, default expression for a formal parameter, entry, formal parameter, function, function call, hiding, identifier, illegal, literal, mode, named parameter association, operator symbol, overloading, package, parameter of a subprogram, qualified expression, renaming declaration, result subtype, subprogram, subprogram specification, subtype, type.

Rationale references: 8.3 Parameter Passing Notations, 11.5 Overload Resolution

Style Guide references: 4.2.1 Minimization of Interfaces, 5.7.3 Overloaded Subprograms, 8.2.5 Overloading in Generic Units


[Ada Information Clearinghouse]

Address any questions or comments to