Search code examples
adadefault-parameters

Where are Default Parameters evaluated in Ada?


So we know Ada supports default parameters like so

procedure Example(param1 : Integer := 1);

But my question is, where the default parameter evaluated? In all languages where I'm familiar, the default parameter is merely inserted into calling code, which requires downstream recompilation if the default parameter is changed. Does Ada use this same approach?

I tried searching the ARM 2012, but couldn't find "default parameter" anywhere in the entire document. So then I checked 6.4 and 6.4.1 where it seems like the ARM calls the relevant part "default expressions". However "default expressions" links to 3.7 Discriminants. This might possibly be used to reduce the amount of times something is defined, however if it's common to two concepts they should do what programmers do and define it separately; this jump is confusing and seems like an error.

Note 59 reads:

The default_expression for a discriminant of a type is evaluated when an object of an unconstrained subtype of the type is created.

Well, that doesn't make any sense in regards to subroutine calls.

So again, when is a "default expression" for a subroutine actually evaluated?


Solution

  • You've been looking in the right place, but you must have missed the important part in RM 6.4 10/2:

    10/2 For the execution of a subprogram call, the name or prefix of the call is evaluated, and each parameter_association is evaluated (see 6.4.1). If a default_expression is used, an implicit parameter_association is assumed for this rule. These evaluations are done in an arbitrary order.