6.2 Formal Parameter Modes
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
[A parameter_specification
declares a formal parameter of mode in, in out, or out.]
Static Semantics
2A parameter is passed either by copy or by reference. [When a parameter is passed by copy, the formal parameter denotes a separate object from the actual parameter, and any information transfer between the two occurs only before and after executing the subprogram. When a parameter is passed by reference, the formal parameter denotes (a view of) the object denoted by the actual parameter; reads and updates of the formal parameter directly reference the actual parameter object.]
A type is a by-copy type if it is an elementary type, or if it is a descendant of a private type whose full type is a by-copy type. A parameter of a by-copy type is passed by copy, unless the formal parameter is explicitly aliased.
A type is a by-reference type if it is a descendant of one of the following:
- a composite type with a subcomponent of a by-reference type;
- a private type whose full type is a by-reference type.
A parameter of a by-reference type is passed by reference, as is an explicitly aliased parameter of any type. Each value of a by-reference type has an associated object. For a value conversion, the associated object is the anonymous result object if such an object is created (see 4.6); otherwise it is the associated object of the operand. In other cases, the object associated with the evaluated operative constituent of the name
or expression
(see 4.4) determines its associated object.
qualified_expression
is ignored for the purposes of determining the associated object; for a conditional_expression
, it is relevant only in that it determines which dependent_expression
defines the associated object.For other parameters, it is unspecified whether the parameter is passed by copy or by reference.
Bounded (Run-Time) Errors
12/3If one name
denotes a part of a formal parameter, and a second name
denotes a part of a distinct formal parameter or an object that is not part of a formal parameter, then the two name
s are considered distinct access paths. If an object is of a type for which the parameter passing mechanism is not specified and is not an explicitly aliased parameter, then it is a bounded error to assign to the object via one access path, and then read the value of the object via a distinct access path, unless the first access path denotes a part of a formal parameter that no longer exists at the point of the second access [(due to leaving the corresponding callable construct).] The possible consequences are that Program_Error is raised, or the newly assigned value is read, or some old value of the object is read.
indexed_component
as in “A(L(6)) := 99;”, where A has bounds 1..3. If the implementation can prove that the value for L(6) in the register is in the range 1..3, then it need not perform the constraint check if it uses the register value. However, if the memory value of L(6) has been changed to 4, and the implementation uses that memory value, then it had better not alter memory outside of A.procedure Move ( Source : in String;
Target : out String;
Drop : in Truncation := Error;
Justify : in Alignment := Left;
Pad : in Character := Space);
-- Copies elements from Source to Target (safely if they overlap)
assignment_statement
assigning one array parameter to another, the implementation has to check which direction to copy at run time, in general, in case the actual parameters are overlapping slices. For example: procedure Copy(X : in out String; Y: String) is
begin
X := Y;
end Copy;
subprogram_body
(see 6.1).subprogram_body
.subprogram_body
(see 6.4.1).